What does SET NOCOUNT ON do?

When you’re working with T-SQL, you’ll often see SET NOCOUNT ON at the beginning of stored procedures and triggers.

What SET NCOUNT ON does is prevent the “1 row affected” messages from being returned for every operation.

I’ll demo it by writing a stored procedure in the Stack Overflow database to cast a vote:

CREATE OR ALTER PROC dbo.usp_InsertVote @PostId INT, @UserId INT, @VoteTypeId INT AS BEGIN INSERT INTO dbo.Votes(PostId, UserId, VoteTypeId, CreationDate) VALUES (@PostId, @UserId, @VoteTypeId, GETDATE()); UPDATE dbo.Users SET LastAccessDate = GETDATE() WHERE Id = @UserId; END GO EXEC usp_InsertVote 1, 1, 1;

When this stored procedure runs, it