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