DF209: SET NOCOUNT ON is missing before the first DML statement.

The topic describes the DF209 T-SQL code analysis rule.

Category

PERFORMANCE

Message

SET NOCOUNT ON is missing before the first DML statement.

Description

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.

Additional information

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.

Noncompliant code example

CREATE PROCEDURE dbo.DemoProcedure
AS
BEGIN
  SELECT id FROM dbo.DemoTable;
END
GO

Compliant solution

CREATE PROCEDURE dbo.DemoProcedure
AS
BEGIN
  SET NOCOUNT ON;
  SELECT id FROM dbo.DemoTable;
END
GO

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?