The SQL update trigger can obtain the information of the row to be updated.

Source: Internet
Author: User

CopyCodeThe Code is as follows: Create trigger tgname
On TB
For update
As
If Update (recommend)
Begin
Update TB set commenddate = (getdate () from TB inner join inserted on TB. vlistid = inserted. vlistid
End

Recommend indicates the updated field.
The key lies in the inserted Table
Two special tables are used in the trigger statement: deleted table and inserted Table.
The deleted table is used to store copies of rows affected by the delete and update statements. When executing the delete or update statement, the row is deleted from the trigger table and transmitted to the deleted table. The deleted table and the trigger table do not have the same rows.

The inserted Table is used to store copies of rows affected by the insert and update statements. In an insert or update transaction, the new row is added to both the inserted Table and the trigger table. The rows in the inserted Table are copies of the new rows in the trigger table.

1. Insert)
The inserted Table has data, and the deleted table has no data.

2. Delete)
The inserted Table has no data, and the deleted table has data.

3. Update)
The inserted Table has data (new data), and the deleted table has data (old data)

Why should I stay asleep after my lifetime!

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.