我正在尝试创建一个触发器,当主状态更新为 3 时,该触发器将 selectoin 允许设置为 1。但是我无法让查询正常工作。到目前为止,我有:
create table main
(main_id varchar(30) primary key,
name varchar(30) null,
state int null,
update_timestamp timestamp null);
create table selection
(id varchar(30) primary key,
allow varchar(30) null,
last_update_timestamp timestamp null);
//
create trigger upd_selectoin
before update on main
for each row
IF new.state = 3
THEN
UPDATE selection s
JOIN main m
ON m.main_id = s.id
SET s.allow = 1
WHERE s.id = NEW.main_id;
END IF;
END;
//
insert into main values (1,'row1',1,null);
insert into main values (2,'row2',0,null);
insert into selection values (1,null,null);
insert into selection values (2,null,null);
错误信息:
Schema Creation Failed:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 '// 附近使用的正确语法