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

后端 未结 7 1405
灰色年华
灰色年华 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:00

    To clarify the problem with @@Identity:

    For instance, if you insert a table and that table has triggers doing inserts, @@Identity will return the id from the insert in the trigger (a log_id or something), while scope_identity() will return the id from the insert in the original table.

    So if you don't have any triggers, scope_identity() and @@identity will return the same value. If you have triggers, you need to think about what value you'd like.

提交回复
热议问题