Copy Code code 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: Deleted tables and inserted tables.
The Deleted table is used to store a copy of the rows affected by the DELETE and UPDATE statements. When the delete or UPDATE statement is executed, 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 one insert or update transaction, new rows are 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. Inserting operation (insert)
Inserted table has data, deleted table has no data
2. Delete operation (delete)
Inserted table has no data, deleted table has data
3. Update operation (updated)
Inserted table has data (new data), deleted table has data (old data)
Why do you sleep before you die?