Sunday, 14 December 2014

SET NOCOUNT

Stops the message that shows the count of the number of rows affected by a Transact-SQL statement or stored procedure from being returned as part of the result set.

Syntax: SET NOCOUNT { ON | OFF } 

Remarks
When SET NOCOUNT is ON, the count is not returned. When SET NOCOUNT is OFF, the count is returned.
The @@ROWCOUNT function is updated even when SET NOCOUNT is ON.

Examples
The following example prevents the message about the number of rows affected from being displayed.

USE AdventureWorks2012;
GO

SET NOCOUNT OFF;
GO

-- Display the count message.
SELECT TOP(5)LastName
FROM Person.Person
WHERE LastName LIKE 'A%';
GO

-- SET NOCOUNT to ON to no longer display the count message.
SET NOCOUNT ON;
GO

SELECT TOP(5) LastName
FROM Person.Person
WHERE LastName LIKE 'A%';
GO

-- Reset SET NOCOUNT to OFF
SET NOCOUNT OFF;
GO

Related Posts:

  • UDF For Splitting Comma Seperated Values CREATE FUNCTION [dbo].[fnSplit](        @sInputList VARCHAR(8000) -- List of delimited items      , @sDelimiter VARCHAR(8000) = ',' -- delimiter that separates items&nbs… Read More
  • SET NOCOUNT Stops the message that shows the count of the number of rows affected by a Transact-SQL statement or stored procedure from being returned as part of the result set.Syntax: SET NOCOUNT { ON | OFF } RemarksWhen SET NOCOUN… Read More
  • Schema in SQL Server 2012 IntroductionIn this article I describe schemas in SQL Server 2012. A schema is like a container that contains database objects like tables, views etc. So let us learn about schemas, creation of schemas, how to alter schemas … Read More
  • Delete duplicate rows in SQL Server Introduction Some time some duplicate data may inserted in the SQL table. But its harmful for you and your application too. So how to remove the duplicate rows in your table. Description Take a look in the following tabl… Read More
  • Built-in Functions (Transact-SQL) CHARINDEX - Searches an expression for another expression and returns its starting position if found. DECLARE @FullName VARCHAR(100) SET @FullName = 'Clark Kent' select CHARINDEX(' ', @FullName) Output – 6 STUFF… Read More

0 comments:

Post a Comment