What is the difference between Scope_Identity(), Identity(), @@Identity, and Ident_Current()?

后端 未结 7 1300
灰色年华
灰色年华 2020-11-22 06:49

I know Scope_Identity(), Identity(), @@Identity, and Ident_Current() all get the value of the identity column, but I woul

相关标签:
7条回答
  • 2020-11-22 07:23

    Here is another good explanation from the book:

    As for the difference between SCOPE_IDENTITY and @@IDENTITY, suppose that you have a stored procedure P1 with three statements:
    - An INSERT that generates a new identity value
    - A call to a stored procedure P2 that also has an INSERT statement that generates a new identity value
    - A statement that queries the functions SCOPE_IDENTITY and @@IDENTITY The SCOPE_IDENTITY function will return the value generated by P1 (same session and scope). The @@IDENTITY function will return the value generated by P2 (same session irrespective of scope).

    0 讨论(0)
提交回复
热议问题