Click or drag to resize

SA0012 : Use SCOPE_IDENTITY() instead @@IDENTITY

The topic describes the SA0012 analysis rule.

Message

Use SCOPE_IDENTITY() instead @@IDENTITY

Description

The rule checks for use of @@IDENTITY server variable. It is recommended to use SCOPE_IDENTITY() instead. @@IDENTITY is not limited to a specific scope and is not a reliable indicator of the most recent user-created identity if the column is part of a replication article.

Scope

The rule has a Batch scope and is applied only on the SQL script.

Parameters

Rule has no parameters.

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Design Rules

Additional Information

There is no additional info for this rule.

Example Test Script
SQL
1-- SA0012 analysis rule is voilated here
2SELECT @@IDENTITY
3
4-- OK
5SELECT SCOPE_IDENTITY()

Analysis Results

 MessageLineColumn
1SA0012 : Use SCOPE_IDENTITY() instead @@IDENTITY.27
See Also

Other Resources