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.

 

About the N Row(s) Affected” output message in SQL Server

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.

 

How to Suppress the Message

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 Rows Affected Output Message in SQL Server - Article on SQLNetHub
Figure 1: Running a T-SQL Statement with the Default NOCOUNT Setting.

 

How to Suppress the N Rows Affected Output Message in SQL Server - Article on SQLNet
Figure 2: Running a T-SQL Statement After Setting NOCOUNT to ON.

 

Strengthen you SQL Server Development Skills – Enroll to 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
(Lifetime Access, Certificate of Completion and more!)

Learn More

 

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 (2 votes, average: 5.00 out of 5)

Loading...

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

© SQLNetHub