>>The best way to generate automatic primary key values is to use auto-increment integer key fields. You can get ID value using "SELECT @@IDENTITY" query to SQL Server.
>
>I wouldn't say thats the best way, what if your INSERT triggers another INSERT somewhere else? Now the @@IDENTITY will be the key of another table, not the one you expected.
So how would one handle that situation Mike? I was reading about @@IDENTITY in "Inside SQL Server" just the other day and felt that there were some "dicey" situations possible, but the book made no mention of needing much care for particular situations so I *assumed* that it must be a non-issue (the only issue they really mentioned was that IDENTITY values could have gaps in numbering). My guess is that naming the table in the indentity select would be the way around it.
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement