Click or drag to resize

SA0234 : It is recommended to use the new TOP(expression) clause syntax

The topic describes the SA0234 analysis rule.

Message

It is recommended to use the new TOP(expression) clause syntax

Description

This rule checks for usage of old style TOP clause without parentheses around the expression.

For backward compatibility, the parentheses are optional in SELECT statements.

It is recommended to always use parentheses for TOP in SELECT statements for consistency as the parentheses are required in INSERT, UPDATE, MERGE, and DELETE statements.

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.

Categories

Design Rules, New Rules

Additional Information

There is no additional info for this rule.

Example Test Script
SQL
 1SELECT TOP 9  
 2           LastName, FirstName, JobTitle, Department
 3FROM       HumanResources.vEmployeeDepartment
 4ORDER BY LastName ASC
 5
 6SELECT TOP 12  
 7           LastName, FirstName, JobTitle, Department
 8FROM       HumanResources.vEmployeeDepartment
 9ORDER BY LastName ASC
10
11SELECT TOP (5)  
12           LastName, FirstName, JobTitle, Department
13FROM       HumanResources.vEmployeeDepartment
14
15SELECT TOP 11    /*IGNORE:SA0234(LINE)*/
16           LastName, FirstName, JobTitle, Department
17FROM       HumanResources.vEmployeeDepartment
18
19SELECT
20        F.Code, 
21        F.CustNum, 
22        SupplierCode = ((SELECT TOP 1 S.SupplierCode FROM Supplier S WHERE S.FacilityCode = F.FacilityCode))
23FROM Facility F;

Analysis Results

 MessageLineColumn
1SA0234 : It is recommended to use the new TOP(expression) clause syntax.17
2SA0234 : It is recommended to use the new TOP(expression) clause syntax.67
3SA0234 : It is recommended to use the new TOP(expression) clause syntax.117
4SA0234 : It is recommended to use the new TOP(expression) clause syntax.2225
See Also

Other Resources