SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Scope_Identity vs @@identity
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

janets20
Starting Member

12 Posts

Posted - 06/19/2010 :  22:10:51  Show Profile  Reply with Quote
Hi,

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

Regards

Jane

tkizer
Almighty SQL Goddess

USA
36652 Posts

Posted - 06/20/2010 :  00:05:58  Show Profile  Visit tkizer's Homepage  Reply with Quote
@@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 - 06/20/2010 :  22:57:11  Show Profile  Reply with Quote
spam removed
Go to Top of Page

Lumbago
Norsk Yak Master

Norway
3271 Posts

Posted - 06/21/2010 :  02:32:53  Show Profile  Reply with Quote
@@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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000