SA0158 : Deprecated usage of space as separator for table hints. Use a comma instead of space |
![]() |
Using a space as a separator for table hints can lead to SQL parsing errors and unintended query behavior.

In T-SQL code, table hints are used to direct the query optimizer on how to process certain tables in a query. However, using an incorrect separator, such as a space, between table hints can cause SQL Server to misinterpret the intended hints. This can result in syntax errors or the database ignoring some table hints, leading to unexpected query results.
For example:
1-- Example of problematic query using space as a separator 2SELECT * FROM TableName WITH (NOLOCK INDEX = IX_IndexName);
In this example, using a space between NOLOCK and INDEX is incorrect. SQL Server expects a comma to separate multiple hints, leading to potential parsing issues or ignored hints.
-
Potential syntax errors if incorrect separation is used, impacting query execution.
-
Risk of hints being ignored, affecting performance and consistency in query results.

Ensure table hints are specified using the WITH keyword and commas as separators to avoid parsing errors and ensure expected behavior.
Follow these steps to address the issue:
-
Identify the query where table hints are used with spaces as separators instead of commas.
-
Replace spaces between multiple table hints with commas to correct the syntax.
-
Ensure that the table hints follow the WITH keyword and are enclosed in parentheses.
-
Review and test the query to confirm that the hints are correctly applied and the query executes as expected.
For example:
1-- Corrected query using commas between hints 2SELECT * FROM TableName WITH (NOLOCK, INDEX = IX_IndexName);

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, Deprecated Features, Bugs


SQL
1SELECT au_id 2FROM dbo.authors with ( UPDLOCK ,PAGLOCK ) -- Usage of the WITH keyword is recommended 3 4SELECT au_id 5FROM dbo.authors WITH( UPDLOCK PAGLOCK ) 6 7 8INSERT INTO Person WITH (TABLOCK, HOLDLOCK) (FirstName) 9VALUES ('Bruce'); |

Message | Line | Column | |
---|---|---|---|
1 | SA0158 : Deprecated usage of space as separator for table hints. Use a comma instead of space. | 5 | 30 |
2 | SA0158 : Deprecated usage of space as separator for table hints. Use a comma instead of space. | 5 | 38 |
