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.

 

Learn more tips like this! Check our Online Course!

Check our online course titled “Essential SQL Server Development Tips for SQL Developers” (special limited-time discount included in link).

Sharpen your SQL Server database programming skills via a large set of tips on T-SQL and database development techniques. The course, among other, features over than 30 live demonstrations!

Essential SQL Server Development Tips for SQL Developers - Online Course

Enroll Now with Discount!

 

Featured Online Courses:

 

 

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