SA0008 : Deprecated syntax string_alias = expression

The topic describes the SA0008 analysis rule.

Message

Deprecated syntax string_alias = expression

Description

This rule checks T-SQL script for use of column aliasing where the name of the expression uses a string value. The syntax is deprecated and it is recommended to use quoted identifiers instead.

The following syntax is deprecated:

SQL
1SELECT 'alias_for_col' = au_id + au_id
2FROM dbo.authors

Recommended alternatives are:

1expression [AS] column_alias 
2expression [AS] [column_alias]
3expression [AS] "column_alias"
4expression [AS] 'column_alias'
5column_alias = expression

How to fix

Rewrite the expression alias to use one of the recommended column alias syntaxes instead of the deprecated `string_alias = expression` column alias syntax.

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.

Effort To Fix
2 minutes per issue.
Categories

Design Rules, Deprecated Features, Code Smells

Additional Information

There is no additional info for this rule.

Example Test SQL
SQL
 1-- Deprecated alias syntax is used here
 2SELECT     'alias_for_col'=au_id+au_id
 3FROM       dbo.authors
 4
 5-- Deprecated alias syntax is used here,but ignored, because all rules at the violation line are suppressed
 6SELECT     'alias_for_col'=au_id+au_id, au_id --IGNORE:*(LINE)
 7FROM       dbo.authors
 8
 9-- OK
10SELECT     au_id+au_id AS alias_for_col
11FROM       dbo.authors
12
13-- OK
14SELECT     au_id+au_id AS [alias_for_col]
15FROM       dbo.authors
16
17-- OK
18SELECT     au_id+au_id AS "alias_for_col"
19FROM       dbo.authors
20
21-- OK
22SELECT     au_id+au_id AS 'alias_for_col'
23FROM       dbo.authors
24
25-- OK
26SELECT     column_alias=expression
27FROM       dbo.authors

Analysis Results
  Message Line Column
1 SA0008 : Deprecated syntax string_alias = expression. 2 11
See Also

Other Resources