First of all, when discussing the three methods, you need to understand two concepts: session and scope. Session means the current connection that's executing the command. Scope means the immediate context of a command. Every stored procedure call executes in its own scope, and nested calls execute in a nested scope within the calling procedure's scope. Likewise, a SQL command executed from an application or SSMS executes in its own scope, and if that command fires any triggers, each trigger executes within its own nested scope.
Now that these two concepts are defined, here are the differences between the three identity retrieval methods:
To illustrate, imagine the following scenario: You execute an insert command on a Customer table, which fires an insert trigger that inserts a default Order for that customer in the Order table. Immediately after, before you execute another command, another session does the same thing.
For most scenarios most of the time, what you will want is the value returned by scope_identity().
Remember Me
a@href@title, i, strike, u
Copyright © 2003-2008 Falafel Software Inc.
Subscribe to Falafel Blogs
The opinions expressed herein are Falafel's employees own personal opinions and do not represent Falafel Software's view in any way in case they go bananas!