Instead of trigger in SQL Server loses SCOPE_IDENTITY?

后端 未结 6 2055
走了就别回头了
走了就别回头了 2020-12-01 10:30

I have a table where I created an INSTEAD OF trigger to enforce some business rules.

The issue is that when I insert data into this table, SCOPE_I

6条回答
  •  萌比男神i
    2020-12-01 11:32

    Use @@identity instead of scope_identity().

    While scope_identity() returns the last created id in the current scope, @@identity returns the last created id in the current session.

    The scope_identity() function is normally recommended over the @@identity field, as you usually don't want triggers to interfer with the id, but in this case you do.

提交回复
热议问题