SQL Server trigger update method to determine whether a column is updated

Source: Internet
Author: User

Every one know's that: in the trigger, I may be changed because of the value of a field. I will trigger this trigger. OK. We will write if Update (column1) this statement is OK, but you need to know that it is based on your SQL statement. That is to say, the value of column1 in your database is, if you use an SQL statement to update column1 to A, then the if Update (column1) is still valid. I have repeatedly tried to find that if Update (column1) cannot judge your inserted
If it is the same as column1 in updated, it only determines whether set column1 = 'X' exists in your update statement. If it is true or not, false is returned.

So if you want to determine whether the original value is changed in this update, you should use this judgment

If (select count (*) from inserted a inner join deleted B on A. Primary Key = B. Primary Key and A. column1 = B. column1)> 0)

By making such a judgment, you will ensure that your value will return true only when it is changed.

Related Article

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.