Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SET NOCOUNT Expand / Collapse
Author
Message
Posted Wednesday, September 1, 2010 8:45 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 1:41 PM
Points: 202, Visits: 568
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
Post #978852
Posted Wednesday, September 1, 2010 9:43 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: 2 days ago @ 12:03 PM
Points: 621, Visits: 2,127
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.
Post #978924
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse