Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: .NET
Expertise: Beginner
Feb 8, 2005



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Obtain the Correct Identity Column Value for a Newly Inserted Row

Both select scope_identity and select @@identity return the identity column value of a newly inserted row. However, @@identity is not reliable because it works in a session level.

So, suppose stored procedure sp1 contains an insert statement, and after the insert statement, there is a call to another stored procedure, sp2.

Assume that sp2 also contains insert statement. Now at the end of sp1, retrieving sp2 not for sp1. But using select scope_identity() results in the identity column value for the insert statement in sp1.

This is why it's always preferable to use select scope_identity() instead of select @@identity.

Jaya Nehru Kumar
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date