我尝试创建一个日期时间字段,只有在某个字段发生更改时才会自动更新当前时间。
似乎我有语法错误。
CREATE OR ALTER TRIGGER last_progress_date
ON wp_task_mgr
AFTER UPDATE
AS BEGIN
IF UPDATE (progress_percentage)
SET last_progress_date = GETDATE()
END
答案 0 :(得分:0)
为了将来参考,我在这里找到答案:
https://dba.stackexchange.com/questions/125203/simple-trigger-to-update-two-columns-in-one-table
MySQL查询:
DELIMITER //
CREATE TRIGGER trig_1 before insert
ON <table_name> FOR EACH ROW
BEGIN
IF new.due_date is not null and new.end_date='' then
set new.end_date=new.due_date;
end if;
IF new.end_date is not null and new.due_date='' then
set new.due_date=new.end_date;
end if;
END;
//
DELIMITER //
CREATE TRIGGER trig_2 before update
ON <table_name> FOR EACH ROW
BEGIN
IF new.due_date <>old.due_date then
set new.end_date=new.due_date;
end if;
IF new.end_date <> old.end_date then
set new.due_date=new.end_date;
end if;
END;
//