date_modified
我正在一个应该更新列的表上创建一个触发器。下面的代码是最好的方法吗?我这样做对吗?
IF EXISTS(SELECT * FROM DELETED) --checking if this is an update, not insert
BEGIN
IF NOT(UPDATE(date_modified)) -- checking if desired column was not updated
BEGIN
DECLARE @updatedID int
SELECT @updatedID = ID FROM deleted -- fetching updated record ID
UPDATE table SET date_modified=GETDATE() WHERE ID=@updatedID -- updating desired column
END