rspec/rules/S4108/tsql/rule.adoc

21 lines
563 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
``++@@IDENTITY++`` returns the last identity column value created on a connection, regardless of the scope. That means it could return the last identity value you produced, or it could return a value generated by a user defined function or trigger, possibly one fired because of your insert. In order to access the last identity value created in your scope, use ``++SCOPE_IDENTITY()++`` instead.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
INSERT ...
SET @id = @@IDENTITY -- Noncompliant
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
INSERT ...
SET @id = SCOPE_IDENTITY()
----