有人可以告诉我这个触发器声明有什么问题吗?
DELIMITER //
CREATE TRIGGER something AFTER INSERT ON sometable
FOR EACH ROW
BEGIN
DECLARE var INT DEFAULT 0;
SET var = SELECT COUNT(*) FROM anothertable;
IF var=0 THEN
INSERT INTO anothertable values(`x`,`y`,`z`);
END IF;
END//
我一直收到错误,说我有语法错误......
答案 0 :(得分:1)
尝试将SELECT语句放在括号中:
DELIMITER //
CREATE TRIGGER something AFTER INSERT ON sometable
FOR EACH ROW
BEGIN
DECLARE var INT DEFAULT 0;
SET var = (SELECT COUNT(*) FROM anothertable);
IF var=0 THEN
INSERT INTO anothertable values('x','y','z');
END IF;
END//