Saturday, July 23, 2011

What does set nocount on does in Sybase ASE or What is the use of nocount set option in Sybase ASE?

Sometimes when we check the system stored procedures we usually find something like this written -

set nocount on

among the first few lines of the stored procedure and you might be wondering what this set option is trying to achieve because when we try to write stored procedures we don't seem to use this set option.

To give the answer to this simple question we will first take your attention towards a very simple query -

select * from MyTAB

where MyTAB is a dummy table with only two fields EmpId and EmpAge, both being integers. This table has currently 100 rows. Now
when you execute a select on this table as shown above what do you happen to see?

Well, we will get 100 rows from this table selected and a message 100 rows effected. Now, this is one of the messages that are usually generated by Sybase ASE server as information to the users, which are usually ignored by most of our applications but increase unnecessary network traffic. So, is there a way to remove this information messages? Yes, nocount is the set option which does the job for us. So simply turn this set option on when you dont need these information messages else turn it off. Simple and useful, isn't it?

1 comment: