我正在尝试创建一个触发器,如果没有票据小于成人号,那么值1将被插入到trig表中。但是,我收到一个错误。代码是:
CREATE TRIGGER ch
BEFORE INSERT
ON packagebooking
IF(tick.tickets<packagebooking.Adult
AND tick.Package_id=packagebooking.Package_id)
Begin atomic
insert into trig values(1)
MySQL说:文档
#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 'IF(tick.tickets<packagebooking.Adult
AND tick.Package_id=packagebooking.Pa' at line 4.
我应该做些什么改变?
答案 0 :(得分:1)
您的触发器创建语法有错误,将IF语句放在FOR EACH ROW中,如下所示:
CREATE TRIGGER ch BEFORE INSERT
ON `database`.`table`
FOR EACH ROW BEGIN
IF(tick.tickets<packagebooking.Adult
AND tick.Package_id=packagebooking.Package_id)
THEN Begin atomic
insert into trig values(1)
END IF;
END;