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 2005 Forums
 Transact-SQL (2005)
 How can i get ID that i inserted a record ?

Author  Topic 

oguzkaygun
Yak Posting Veteran

53 Posts

Posted - 2010-03-14 : 10:51:25
Hello
How can i get ID that i inserted a record ?
Select @@Identity ?
Or Select Scope Identity ?
Which one is more good ?
Thanks

hamid.y
Starting Member

22 Posts

Posted - 2010-03-14 : 13:37:53
hi,
I myself used @@Identity and it works and in my openion its much better than scope Identity because when microsoft did something and make it that much easy and rather optemized, why making trouble?

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-03-14 : 14:18:52
@@Identity will give you the wrong value if your table has a trigger that inserts into another table (which uses an Identity). Even if you table does not have a trigger it might do in the future - so using @@Identity you may be creating a bug for the future.

Use scope_identity() to avoid this problem. In all other regards it is the same as @@Identity, so I can't think of any reason NOT to use scope_identity()!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-15 : 09:43:14
see this

http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -