Skip to content

SA0235 : Consider using the AS keyword to specify a column alias instead of the column_alias = expression syntax

Using column_alias = expression syntax may reduce readability and does not align with the ANSI SQL standard, which recommends the AS keyword for column aliasing.

Using column_alias = expression syntax in T-SQL scripts may lead to confusion and poor readability. Although this syntax is legal in SQL Server, it does not conform to the SQL ANSI standard, which suggests using the AS keyword for aliasing columns.

For example:

-- Example of problematic query using assignment operator for aliasing
SELECT column1 = expression1
FROM TableName;

The example above can be misleading because it resembles variable assignment rather than simple aliasing. It is not easily recognizable to those familiar with standard SQL conventions, making it harder to maintain consistency across different RDBMS systems.

  • Decreases readability and increases potential for misunderstanding among team members who expect standard syntax.

  • May lead to compatibility issues when migrating code to different systems that adhere strictly to ANSI SQL.

Use the AS keyword for column aliasing to improve readability and maintain SQL ANSI standard compliance.

Follow these steps to address the issue:

1.Identify any instances in your T-SQL queries where the column_alias = expression syntax is used.

2.Replace the format column_alias = expression with expression AS column_alias .

3.Ensure that all team members are aware of the change and adhere to using the AS syntax for consistency and readability.

For example:

-- Problematic query using assignment operator for aliasing
SELECT column1 = expression1
FROM TableName;
-- Corrected query using AS keyword for aliasing
SELECT expression1 AS column1
FROM TableName;

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.

2 minutes per issue.

Design Rules, Code Smells

There is no additional info for this rule.

-- OK
SELECT au_id+au_id AS alias_for_col
FROM dbo.authors
-- OK
SELECT au_id+au_id AS [alias_for_col]
FROM dbo.authors
-- OK
SELECT au_id+au_id AS "alias_for_col"
FROM dbo.authors
-- OK
SELECT au_id+au_id AS 'alias_for_col'
FROM dbo.authors
-- OK
SELECT column_alias=expression
FROM dbo.authors
-- column_alias = expression syntax is used here, but ignored, because all rules at the violation line are suppressed.
SELECT alias_for_col=au_id+au_id, au_id --IGNORE:*(LINE)
FROM dbo.authors
-- Deprecated alias syntax is used here. Reported by SA0008
SELECT 'alias_for_col'=au_id+au_id
FROM dbo.authors
DECLARE @variable int
SELECT @variable = 1
  Message Line Column
1 SA0235 : Consider using the AS keyword to specify a column alias instead of the column_alias = expression syntax. 18 23

Analysis Rules