I have many procedures that has set nocount on.
Is it necessary to turn it off at the end of stored procedure?
e.g.:
create procedure DummyProc
as
begin
set nocount on
...
set nocount off
end
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
set nocount onwill disable theX rows affected.message SQL returns. This message is suppressed, in some cases, due to undesired effects with the client executing the stored proc.set nocount offwill undo this suppression. However,set nocount onis a scope setting, and by default, will be turned off when leaving the scope anyway.Now, is
set nocount offnecessary? No, as any new commands executed will be in a different scope, and by defaultset nocount offis always in effect. But as stated above in comments, it’s considered a good practice, just to explicitly indicate that this setting will return to normal when the proc is finished executing.