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 01, 2010 8:45 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, April 11, 2014 6:12 PM
Points: 197, Visits: 550
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 01, 2010 9:43 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 8:21 AM
Points: 547, Visits: 1,877
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