SA0079 : Avoid using column numbers in ORDER BY clause
The topic describes the SA0079 analysis rule.
Avoid using column numbers in ORDER BY clause
The rule checks for ORDER BY clauses which reference select list column using the column number instead of the column name.
The column numbers in the ORDER BY clause as it impairs the readability of the SQL statement. Further, changing the order of columns in the SELECT list has no impact on the ORDER BY when the columns are referred by names instead of numbers. Consider the following example, in which the second query is more readable than the first one:
1SELECT OrderID, OrderDate FROM Orders 2ORDER BY 2 3 4SELECT OrderID, OrderDate FROM Orders 5ORDER BY OrderDate
Review the ORDER BY clause and change the number with the column name or column alias name.
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.
Design Rules, Code Smells
There is no additional info for this rule.
1/* Enter T-SQL script to test your analysis rule. */ 2SELECT OrderID, OrderDate FROM Orders 3ORDER BY 2 4 5SELECT OrderID, OrderDate FROM Orders 6ORDER BY OrderDate
No violations found.