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)
 Scope_Identity vs @@identity

Author  Topic 

janets20
Starting Member

12 Posts

Posted - 2010-06-19 : 22:10:51
Hi,

In which scenario does @@identity will fail.Pls explain in detail.Diff bet Scope_Identity vs @@identity

Regards

Jane

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-20 : 00:05:58
@@IDENTITY could be wrong if you have a trigger on the table. If you want it explained in detail, then I'd suggest searching this site for the many articles and threads that discuss this topic.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

niechen861102
Starting Member

9 Posts

Posted - 2010-06-20 : 22:57:11
spam removed
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-06-21 : 02:32:53
@@identity is global. When you ask for @@identity you might get an identity value that was inserted in another statement/stored procedure while scope_identity always gives you the last identity in the current scope. Therefore you shuld always use scope_identity...

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page
   

- Advertisement -