Type: Reprint
The SQL UPDATE trigger can get information about the row being update, and the friend you need can refer to it. Copy CodeThe 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 represents the field being updated.
The key is the inserted table
Two special tables are used in trigger statements: the deleted table and the inserted table.
The Deleted table is used to store copies of the rows affected by the DELETE and UPDATE statements. When you execute a delete or UPDATE statement, the row is removed from the trigger table and transferred to the deleted table. Deleted tables and trigger tables usually do not have the same rows.
The Inserted table is used to store a copy of the 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 row in the Inserted table is a copy of the new row in the trigger table.
1. Insertion operation (insert)
Inserted table with data, deleted table no data
2. Deletion (delete)
Inserted table no data, deleted table has data
3. Update operation
Inserted table with data (new data), deleted table with data (old data)
SQL UPDATE trigger to get information about the row being update