我有这个 MySQL 表:
create table test.customer (
ID INTEGER,
CREATION_TIME DATETIME,
CREATION_USER VARCHAR(50),
CHANGE_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
CHANGE_USER VARCHAR(50),
PRIMARY KEY(ID)
);
我想自动设置用户和时间戳以进行日志记录。我在插入之前确实有一个触发器(实际上只为creation_time编写):
delimiter #
create trigger test.customer_creation
before insert on test.customer
for each row
begin
set NEW.CREATION_TIME = NOW();
IF (NEW.CREATION_USER is null or NEW.CREATION_USER = '')
THEN set NEW.CREATION_USER = USER();
end IF;
end #
delimiter ;
但我真的不想要一个只针对 CHANGE_USER 的触发器。是否有可能设置 CHANGE_USER 类似于:DEFAULT USER()?还是我必须创建一个额外的触发器?