@ Rowcount and "set nocount on" problems caused by the order in which the triggers are used

Source: Internet
Author: User

Generally, @ rowcount and set nocount on are used in triggers. However, if you do not pay attention to the order between them, problems may occur. Today, I wrote a trigger that never worked, and I haven't found the cause for a long time. The Code is as follows:

 

Alter trigger [trg_houses_updated]
On [DBO]. [houses]
After update
As
Begin
Set nocount on;

If @ rowcount = 0
Return;

...
End

 

 

The reason may be the set nocount on, so that @ rowcount does not work. Then, I tried to change the sequence of set nocount on and @ rowcount. The modified code is as follows:

 

1 alter trigger [trg_houses_updated]
2 On [DBO]. [houses]
3 after update
4
5 begin
6 if @ rowcount = 0
7 return;
8
9 set nocount on;
10...
11 end

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.