0

I have a stored proecdure like below:

@userInput int

as
declare isSuperUser int
declare IDs table(
recordID int
);

set isSuper = select isSuper from [User]
if(@isSuper = 1)
Begin
    insert into recordID select * from TableA
End
else
Begin
    insert into recordID select * from TableB
End

select * from recordID

And I would like to add "set noCount on" on every query, so the question is: is the performance in store procedureA equivalent to store procedureB?

store procedureA :

@userInput int

as
declare isSuperUser int
declare IDs table(
recordID int
);
set noCount on
set isSuper = select isSuper from [User]
if(@isSuper = 1)
Begin
    insert into recordID select * from TableA
End
else
Begin
    insert into recordID select * from TableB
End

select * from recordID
set noCount off

store procedureB:

@userInput int

as
declare isSuperUser int
declare IDs table(
recordID int
);
set noCount on
set isSuper = select isSuper from [User]
set noCount off
if(@isSuper = 1)
Begin
    set noCount on
    insert into recordID select * from TableA
    set noCount off
End
else
Begin
    set noCount on
    insert into recordID select * from TableB
    set noCount off
End
set noCount on
select * from recordID
set noCount off
User2012384
  • 4,769
  • 16
  • 70
  • 106

1 Answers1

1

SET NOCOUNT ON prevents the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. For stored procedures that contain several statements that do not return much actual data, or for procedures that contain Transact-SQL loops, setting SET NOCOUNT to ON can provide a significant performance boost, because network traffic is greatly reduced.

TechNet

While storedProcedure is executing , there is no point of sending data back to client, setting noCount On increases performance as it reduces network traffic . In your Store Procedure B you are switching NoCount on to off which increases network traffic.

Suraj Singh
  • 4,041
  • 1
  • 21
  • 36