Detailed description of the trigger deleted table and inserted Table !!!

Source: Internet
Author: User
Create   Trigger Updatedeletetime
On   User
For   Update
As
Begin  
  Update   User   Set Updatetime = ( Getdate ()) From   User   Inner   Join Inserted On   User . Uid = Inserted. uid
End

In the above example, the update operation is performed at the same time, and the modification time is as follows.
The key lies in the inserted Table
Two special tables are used in the trigger statement:DeletedTable andInsertedTable.
The deleted table is used to store Delete and update statements.Duplicate of the affected row. 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 in the trigger table.Copy of the new row.

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).

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.