I have a table with a primary key being a bigint and its set to auto increment (or identity or whatever ms calls it). Is there anyway I can get the ID number that will be assigned to the next Insert before I insert it? I want to use that ID number within another field when inserted.
I hope that makes sense.
Thanks for any help.
Robboare you using a stored procedure?? If so, you can get the id from the @.@.IDENTITY variable
select @.@.IDENTITY|||Sorry, the id won't be allocated until the actual insert
(You have to think of there might be many parallell inserts..)
What you can do is to leave the other field blank
and then create an after-trigger that picks up the inserted id and
updates the other field with it.
Regards
Fredrik|||::Is there anyway I can get the ID number that will be assigned to the next Insert before I
::insert it?
Waht good would this be, given that another instance of the ap etc. could already have used up the number? This ppiece of information is unreliable unless you get into VERY bad programming practices.
Or do you seriously propose to create a table level lock at this moment?
Or have you simply not thought about the consequences of your wish?