显示标签为“possibility”的博文。显示所有博文
显示标签为“possibility”的博文。显示所有博文

2012年3月6日星期二

Any reason not to use SET NOCOUNT ON in a stored procedure?

Is there any reason not to use "SET NOCOUNT ON" in a stored procedure?

The seemingly obvious possibility that it must be OFF to use @.@.ROWCOUNT is countered by the BOL entry which says "The @.@.ROWCOUNT function is updated even when SET NOCOUNT is ON."

That entry also states "For stored procedures that contain several statements that do not return much actual data, this can provide a significant performance boost because network traffic is greatly reduced".

I have always understood that is good practise to have SET NOCOUNT ON is a stored procedure.

So is there any advantage (other than one less line to enter) of not having SET NOCOUNT ON is any stored procedure?

I do not think that the status of the NOCOUNT setting has anything to do with the use of the @.@.rowcount internal; look at this:

Code Snippet

set nocount on

select 1 as [on] union all select 2
select @.@.rowcount as [@.@.rowcount]

set nocount off


select 1 as [off] union all select 2
select @.@.rowcount as [@.@.rowcount]

/*
on
--
1
2

@.@.rowcount
--
2

off
--
1
2

(2 row(s) affected)

@.@.rowcount
--
2

(1 row(s) affected)
*/

I think that we had some old apps that had trouble when multiple ROWCOUNT messages were returned, but I don't really know the details of that. And this trouble had a good deal to do with setting NOCOUNT to ON in those particular applications.


|||

This is just one of those examples of why you should be very specific when you name things.

SET NOCOUNT ON *sounds* like it would suppress the rowcount being taken/stored, but in essense all it does is suppress the message that is sent to the client, so SET ROWCOUNT_MESSAGE OFF would be the best way to name it (or at the very least, the best way to think of it.)

The only advantage of not having it on is if your tools use the message for some purpose. Like if the UI expects to see the message after operations, and actually uses the information, then it is interesting.

|||

Set NOCOUNT ON is used to suppress the feedback message from the Server to Client. It wont affect the @.@.ROWCOUNT global variable.

It is something similar to the oracle's SET FEEDBACK OFF

|||

> So is there any advantage (other than one less line to enter) of not having SET NOCOUNT ON is any stored procedure?

Depend what are you using this sp for. Read the first note.

Updating Data Sources with DataAdapters

http://msdn2.microsoft.com/en-us/library/33y2221y(VS.80).aspx

AMB

|||

>Updating Data Sources with DataAdapters http://msdn2.microsoft.com/en-us/library/33y2221y(VS.80).aspx

Thank you for the refererence! Now a positive reason not to use "SET NOCOUNT ON", it interferes with the edit and update action on a DataAdapter, by causing an exception.

Any other reasons please?

Any possibility?

Any possibility?
Right now I have a 600 MB space free and on my system I have a 6 GB backup
file and I want to restore it on my own system...
I don't have any network where I have place this file and restore it from
there and no DVD which support this 6 GB... any
possibility like when I restore this file the backup file also remove
simultaneously so that space would be there... I am
sure it's not possible but might be some idea from you guys...
thanks
Joh wrote:
> Any possibility?
> Right now I have a 600 MB space free and on my system I have a 6 GB
> backup file and I want to restore it on my own system...
> I don't have any network where I have place this file and restore it
> from there and no DVD which support this 6 GB... any
> possibility like when I restore this file the backup file also remove
> simultaneously so that space would be there... I am
> sure it's not possible but might be some idea from you guys...
> thanks
Why not purchase a small USB hard drive. You can get one for about $129
that will give you the needed space for these type of operations. Or a
second internal hard drive which might be cheaper. Or a friend's
networked PC or laptop.
David G.