rspec/rules/S4108/tsql/rule.adoc
2022-02-04 16:28:24 +00:00

34 lines
780 B
Plaintext

``++@@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.
== Noncompliant Code Example
[source,sql]
----
INSERT ...
SET @id = @@IDENTITY -- Noncompliant
----
== Compliant Solution
[source,sql]
----
INSERT ...
SET @id = SCOPE_IDENTITY()
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]