我在mysql中编写了一个小的触发器函数。这是我编写的触发器查询,并在代码中给出语法错误。
错误:
sql语法有错误;查看与mysql服务器版本对应的手册,以获得使用“cp where”附近的正确语法 cp
. customer_plan_id
=第一个id;
DELIMITER $$
CREATE TRIGGER delete_plan_on_delete_customer
AFTER DELETE ON customers
FOR EACH ROW
BEGIN
DECLARE active_plan INT;
DECLARE first_id INT;
SET active_plan = (SELECT is_active
FROM customer_plans
WHERE customer_id=OLD.customer_id AND first_plan_id=1);
if(active_plan = 0)THEN
SET first_id = (SELECT customer_plan_id
FROM customer_plans
WHERE customer_id=OLD.customer_id AND first_plan_id=1);
DELETE customer_plans cp WHERE `cp`.`customer_plan_id`= first_id;
END IF;
END$$
DELIMITER ;
1条答案
按热度按时间5n0oy7gb1#
的语法
DELETE
mysql文档中的查询是:改变你的想法
DELETE
触发器中的行:旁注:根据我的个人经验,为变量声明默认值是一个好习惯。如: