SET NOCOUNT ON and SQL storded procedure performance
SET NOCOUNT ON
When we run a Select /Insert/ Update or Delete statement against a DB table,we usually get a message like n rows affected .When we run the query in query analyzer for some manual debugging this message is quite helpful.But when u run the same query using a stored procedure,Why do we need this. Obviously this would be an overhead since it would take the network traffic too to convey this message back to the calle (From a DB server to the Data Access layer code) .Usage of SET NOCOUNT ON avoids this problem.It will stop sql server from sending this message back to the calle ,hence improve the performance.So its always a good practice to use SET NO COUNT ON in all your stored procedures to make your application more faster
Example
ALTER PROCEDURE SaveUserData(
@firstName nvarchar (50),
@lastName nvarchar (50),
@emailĀ nvarchar(50))
AS
SET NOCOUNT ON
BEGIN
INSERT INTO USER_MASTER(FIRST_NAME,LAST_NAME,EMAIL) values (@firstName,@lastName,@email)
END
