The topic describes the DF209 T-SQL code analysis rule.
PERFORMANCE
SET NOCOUNT ON is missing before the first DML statement.
It is recommended to use the SET NOCOUNT ON statement at the beginning of a batch of SQL statements to prevent sending unnecessary messages to the client.
It’s important to include SET NOCOUNT ON before the first Data Manipulation Language (DML) statement in stored procedures or triggers. This setting suppresses the “xx rows affected” message that SQL Server returns after executing DML statements. Failing to set NOCOUNT ON can lead to increased network traffic and decreased performance, especially in scenarios involving multiple DML statements or large result sets. Additionally, omitting SET NOCOUNT ON may cause compatibility issues with client applications expecting only result sets.
CREATE PROCEDURE dbo.DemoProcedure
AS
BEGIN
SELECT id FROM dbo.DemoTable;
END
GO
CREATE PROCEDURE dbo.DemoProcedure
AS
BEGIN
SET NOCOUNT ON;
SELECT id FROM dbo.DemoTable;
END
GO