delimiter //
create trigger logsupdate before update on users
for each row
begin
if new.pJailed <> old.pJailed then
set new.jailtime = now();
if new.pVIP <> old.pVIP then
set new.TM2 = now();
if new.pAdminLevel <> old.pAdminLevel then
set new.TM3 = now();
end if;
end;//
delimiter ;
为什么这不起作用?我试图遵循上一个问题的答案,但它在这里给了我错误。
MYSQL 错误
create trigger logsupdate before update on users
for each row
begin
if new.pJailed <> old.pJailed then
set new.jailtime = now();
if new.pVIP <> old.pVIP then
set new.TM2 = now();
if new.pAdminLevel <> old.pAdminLevel then
set new.TM3 = now();
end if;
end;
MySQL says: DOCUMENTATION
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 11
最佳答案
您错过了几个end if;
。另外,end;//
中不需要分号。我还添加了一个 Drop Trigger If Exists
子句以避免错误,以防已存在具有该名称的重复触发器。
这是更正后的触发器(基于 OP's comments ):
delimiter //
DROP TRIGGER IF EXISTS logsupdate //
create trigger logsupdate before update on users
for each row
begin
if new.pJailed <> old.pJailed then
set new.jailtime = now();
end if;
if new.pVIP <> old.pVIP then
set new.TM2 = now();
end if;
if new.pAdminLevel <> old.pAdminLevel then
set new.TM3 = now();
end if;
end//
delimiter ;
关于php - 三个mysql触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52412669/