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
答案 0 :(得分:2)
您错过了几个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 ;