SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SET NOCOUNT


SET NOCOUNT

Author
Message
smallmoney
smallmoney
SSC-Addicted
SSC-Addicted (404 reputation)SSC-Addicted (404 reputation)SSC-Addicted (404 reputation)SSC-Addicted (404 reputation)SSC-Addicted (404 reputation)SSC-Addicted (404 reputation)SSC-Addicted (404 reputation)SSC-Addicted (404 reputation)

Group: General Forum Members
Points: 404 Visits: 574
For the longest time I been creating SP's with the SET NOCOUNT ON option but from the beginning I never knew if you had to turn it back off at the end of the SP. Tried to google this but I was wondering is it required to be set to off at the end of each SP?

Thanks

ex:

CREATE PROCEDURE test123
@date DATETIME
AS
SET NO COUNT ON
SELECT c.gender FROM facebook.dbo.contacts c WHERE c.gender NOT IN ('female','male') AND bday = @date
SET NO COUNT OFF -- <-- is that optional or required
Nevyn
Nevyn
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1590 Visits: 3149
What do you mean by required?

You won't get an error if you dont do it. And depending on what you do with your query window/connection to the DB, you might not even notice a difference in not re-setting it. This is because it only affects the connection your query/procedure is running on.

But it is still probably a good idea to set it back to off, that way your procedure leaves the settings in the same state they were in when it started.
Otherwise, if you are running multiple queries/procedures one after the other in the same query window (or connection), you won't be able to assume what NOCOUNT is set to when the procedure/query begins without knowing what every preceding query/procedure does with it.

In practice, this will likely make little difference. In theory, its better to set it back to off.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search