Skip to content

SA0008 : Deprecated syntax string_alias = expression

Column aliasing syntax that assigns an alias name as a string value (e.g., 'alias name' = expression ) is deprecated in SQL Server. It is recommended to use alternative aliasing syntax for forward compatibility.

The syntax for column aliasing 'alias name' = expression is deprecated in SQL Server and may be discontinued in future version of SQL Server. It should be avoided for forward compatibility and adherence to best practices.

For example:

-- Example of deprecated aliasing
SELECT 'alias_for_col' = au_id + au_id
FROM dbo.authors;

The syntax used in this query is problematic as it employs a string value for aliasing, which is not considered best practice and may be phased out in future versions of SQL Server. Proper aliasing should use one of the aliasing syntax alternatives.

  • Using deprecated syntax can reduce code readability and cause maintenance challenges.

  • Future versions of SQL Server may remove support for this syntax, leading to compatibility issues.

To resolve issues identified by the rule, update the deprecated column aliasing syntax to alternative and supported syntaxes.

Follow these steps to address the issue:

1.Identify the deprecated syntax in your queries where string values are used for aliasing, such as 'alias_for_col' = expression .

2.Replace the deprecated aliasing syntax with the standard AS keyword or quoted identifiers. Use AS to clearly define the alias.

3.Test the updated query to ensure that the aliasing change does not affect the query results or performance.

Recommended alternatives are:

expression [AS] column_alias
expression [AS] [column_alias]
expression [AS] "column_alias"
expression [AS] 'column_alias'
column_alias = expression
[column_alias] = expression

For example:

-- Example of corrected query
SELECT au_id + au_id AS [alias_for_col]
FROM dbo.authors;

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, Deprecated Features, Code Smells

There is no additional info for this rule.

-- Deprecated alias syntax is used here
SELECT 'alias_for_col'=au_id+au_id
FROM dbo.authors
-- Deprecated alias 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
-- 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
  Message Line Column
1 SA0008 : Deprecated syntax string_alias = expression. 2 11

Analysis Rules