September 1, 2010 at 8:45 am
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
September 1, 2010 at 9:43 am
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.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply