SA0017 : SET NOCOUNT ON option in stored procedures and triggers |
![]() |
Set NOCOUNT to ON to optimize performance in SQL Server triggers and stored procedures.

When executing triggers and stored procedures in SQL Server, avoiding unnecessary network traffic is crucial for performance. The SET NOCOUNT ON directive prevents the server from sending messages to the client after each statement, like ‘(*n* row(s) affected)’, which can unnecessarily consume network bandwidth.
Example of a trigger without SET NOCOUNT ON:
1CREATE TRIGGER trgExample 2ON TableName 3FOR INSERT 4AS 5BEGIN 6 SELECT 'Trigger executed'; 7END
In the example above, SQL Server sends a message for every statement executed, which can become a bottleneck if there are many operations. By adding SET NOCOUNT ON, these messages are suppressed, optimizing the execution.
-
Significant reduction in network traffic improves performance, especially for large-scale operations.
-
Enhanced efficiency for procedures and triggers that involve multiple statements.

To optimize performance in SQL Server triggers and stored procedures, the SET NOCOUNT ON option should be implemented to minimize unnecessary network traffic.
Follow these steps to address the issue:
-
Open the trigger or stored procedure you want to optimize in SQL Server Management Studio (SSMS).
-
Locate the beginning of the trigger or stored procedure code block, usually after the AS keyword.
-
Insert SET NOCOUNT ON; at the start of the code block. This directive will suppress the “rows affected” messages, reducing network traffic.
-
Ensure that the rest of the trigger or stored procedure logic remains unchanged, except for the addition of SET NOCOUNT ON;.
-
Save the changes to apply the optimization.
Optimized trigger example with SET NOCOUNT ON:
1CREATE TRIGGER trgExample 2ON TableName 3FOR INSERT 4AS 5BEGIN 6 SET NOCOUNT ON; 7 SELECT 'Trigger executed'; 8END

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.


Performance Rules, Bugs

There is no additional info for this rule.

SQL
1CREATE PROCEDURE HumacnResources.uspGetAllEmployees 2AS 3SET XACT_ABORT ON; 4-- SET NOCOUNT ON; 5SET QUOTED_IDENTIFIER ON; 6 7SELECT LastName, 8 FirstName, 9 JobTitle, 10 Department 11FROM HumanResources.vEmployeeDepartment; |

SQL
1CREATE PROCEDURE HumacnResources.uspGetAllEmployees 2AS 3SET NOCOUNT ON; 4SET XACT_ABORT ON; 5-- SET NOCOUNT ON; 6SET QUOTED_IDENTIFIER ON; 7 8SELECT LastName, 9 FirstName, 10 JobTitle, 11 Department 12FROM HumanResources.vEmployeeDepartment; |

Message | Line | Column | |
---|---|---|---|
1 | SA0017 : SET NOCOUNT ON option in stored procedures and triggers. | 1 | 0 |
