SA0008 : Deprecated syntax string_alias = expression
Introduction
Section titled “Introduction”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.
Description
Section titled “Description”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 aliasingSELECT 'alias_for_col' = au_id + au_idFROM 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.
How to fix
Section titled “How to fix”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] = expressionFor example:
-- Example of corrected querySELECT 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.
Parameters
Section titled “Parameters”Rule has no parameters.
Remarks
Section titled “Remarks”The rule does not need Analysis Context or SQL Connection.
Effort To Fix
Section titled “Effort To Fix”2 minutes per issue.
Categories
Section titled “Categories”Design Rules, Deprecated Features, Code Smells
Additional Information
Section titled “Additional Information”There is no additional info for this rule.
Example Test SQL
Section titled “Example Test SQL”-- Deprecated alias syntax is used hereSELECT 'alias_for_col'=au_id+au_idFROM dbo.authors
-- Deprecated alias syntax is used here,but ignored, because all rules at the violation line are suppressedSELECT 'alias_for_col'=au_id+au_id, au_id --IGNORE:*(LINE)FROM dbo.authors
-- OKSELECT au_id+au_id AS alias_for_colFROM dbo.authors
-- OKSELECT au_id+au_id AS [alias_for_col]FROM dbo.authors
-- OKSELECT au_id+au_id AS "alias_for_col"FROM dbo.authors
-- OKSELECT au_id+au_id AS 'alias_for_col'FROM dbo.authors
-- OKSELECT column_alias=expressionFROM dbo.authorsAnalysis Results
Section titled “Analysis Results”| Message | Line | Column | |
|---|---|---|---|
| 1 | SA0008 : Deprecated syntax string_alias = expression. | 2 | 11 |