How to Suppress the “N Row(s) Affected” Output Message in SQL Server

How to Suppress the “N Row(s) Affected” Output Message in SQL Server

How to Suppress the “N Row(s) Affected” Output Message in SQL Server

Sometimes, when working with T-SQL scripts, you might want to skip the message “(N row(s) affected)” message. This article explains how to suppress the “N Row(s) Affected” output message in SQL Server.

 

Explanation

You get this message when you execute T-SQL statements or stored procedures that they affect rows. To this end, SQL Server returns the number of records which were affected by the database operation you performed.

 

The short answer

If you want to suppress this message, then you can use the “SET NOCOUNT” statement.

 

An Example

So, for example you can try something like this:

SET NOCOUNT ON;

-- Your query goes here

SET NOCOUNT OFF;

 

Below, you can see an example with screenshots that illustrates the above

 

How to Suppress the "N Row(s) Affected" Output Message in SQL Server
Figure 1: Running a T-SQL Statement with the Default NOCOUNT Setting.

 

How to Suppress the "N Row(s) Affected" Output Message in SQL Server
Figure 2: Running a T-SQL Statement After Setting NOCOUNT to ON.

 

Featured Database Productivity Tools

Develop T-SQL code faster with Snippets Generator: Create and modify T-SQL snippets for use in SQL Management Studio, fast, easy and efficiently.

Snippets Generator - SQL Snippets Creation Tool

Learn more

 

Dynamic SQL Generator: Convert static T-SQL code to dynamic and vice versa, easily and fast.

Dynamic SQL Generator: Easily convert static SQL Server T-SQL scripts to dynamic and vice versa.

Learn more

 

Did you find this article useful and interesting? Feel free to leave your comment!

If you enjoy my SQL Server administration tips and articles, I have something special just for you. It is one of my eBooksand it is called “Administering SQL Server“. Check it out!

Subscribe to our newsletter and stay up to date with our latest articles on SQL Server and related technologies!

Check out our latest software releases! All our software tools have free trial versions to download.

 

Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Loading...

Reference: SQLNetHub.com (https://www.sqlnethub.com)

© SQLNetHub

Artemakis Artemiou
Artemakis Artemiou is a Senior SQL Server and Software Architect, Author, and a 9 Times Microsoft Data Platform MVP (2009-2018). He has over 15 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and TechHowTos.com. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Artemakis's official website can be found at aartemiou.com.