Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Regarding Identity column value retreival

Author  Topic 

ourspt
Starting Member

33 Posts

Posted - 2005-02-21 : 01:40:00
Hi,

I am working on a .NET project for order manangement system. There will be multiple users accessing the application simultaneously. We have primary key columns as identity columns in most of our tables in our database. When we create new records, in our SPs we are doing an insert and to get the value of the Primary Key immediately after the insert, we are retrieving the last inserted identity value and using it in the rest of the procedure.

Which one is the best to retrieve the value of the record just inserted - @@Identity, Scope_Identity OR Ident_Current

We should have the right column value considering there will be multiple inserts in the tables precisely at the same, say, micro second. There should be no overlaps where the id value generated for one user/session etc should not be retrieved for another user or session etc.

Please let us know what is the best to use in our condition.

Thanks
oursmp

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-21 : 04:09:31
use Scope_Identity(). that will give you the last id in the current batch.

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -