Skip to content

SA0160 : Deprecated use of @, @@, or names that begin with @@ as Transact-SQL identifiers

Identifiers that start with @ or @@ in T-SQL can lead to confusion and errors in code interpretation.

In T-SQL code, @ is commonly used for declaring and referencing local variables, while @@ is used for system functions (or global variables like @@SERVERNAME ). Misusing these conventions by naming tables, columns, or user-defined variables in a similar manner can cause conflicts or unexpected behavior, as these symbols have predefined meanings.

For example:

-- Example of problematic use of identifiers
SELECT @@someGlobalVar FROM MyTable;
CREATE TABLE @myTable (ID INT);

In the first example, using @@ suggests a system function, which can be misleading if not correctly defined. In the second example, using @myTable can cause confusion, as it mimics local variable syntax, leading to potential misinterpretation within scripts or stored procedures.

  • Creates ambiguity in distinguishing between system functions and user-defined identifiers.

  • Increases risk of syntax errors or logical errors in queries and stored procedures.

  • Can lead to maintenance challenges and lower code readability.

Avoid using identifiers that start with @ or @@ to prevent confusion and errors in T-SQL code interpretation.

Follow these steps to address the issue:

1.Review the reported identifier and understand its current usage within your database scripts or code.

2.Rename the identifier to a more descriptive and unique name that does not begin with @ or @@ . This will ensure it is not mistaken for a local or system-defined variable.

3.Update all references to the renamed identifier within your database objects, such as tables, stored procedures, and functions, to ensure consistency and prevent errors.

For example:

-- Example of corrected query
CREATE TABLE MyTable (ID INT);
SELECT someGlobalVar FROM MyTable;

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

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.

3 minutes per issue.

Design Rules, Naming Rules, Deprecated Features, Bugs

Deprecated Database Engine Features

Discontinued Database Engine Functionality

declare @ as int, @@ as int, @@a bit ,@@b int
  Message Line Column
1 SA0160 : Deprecated use of @, @@, or names that begin with @@ as Transact-SQL identifiers. 1 8
2 SA0160 : Deprecated use of @, @@, or names that begin with @@ as Transact-SQL identifiers. 1 18

Analysis Rules