Autoincrementing hierarchical IDs on SQL Server
Posted
by Ville Koskinen
on Stack Overflow
See other posts from Stack Overflow
or by Ville Koskinen
Published on 2010-03-25T09:22:20Z
Indexed on
2010/03/25
9:23 UTC
Read the original article
Hit count: 436
Consider this table on SQL Server
wordID aliasID value
===========================
0 0 'cat'
1 0 'dog'
2 0 'argh'
2 1 'ugh'
WordID is a id of a word which possibly has aliases. AliasID determines a specific alias to a word.
So above 'argh' and 'ugh' are aliases to each other.
I'd like to be able to insert new words which do not have any aliases in the table without having to query the table for a free wordID value first. Inserting value 'hey' without specifying a wordID or an aliasID, a row looking like this would be created:
wordID aliasID value
===========================
3 0 'hey'
Is this possible and how?
© Stack Overflow or respective owner