我怎么能这样做触发删除验证

时间:2016-10-09 13:47:01

标签: mysql phpmyadmin

我是论坛的新手,我有以下问题,我希望在删除租约表位置后,我会进入表格电影并让列情况变得可用,但如果我有代码在另一个寄存器中表格位置的电影,我仍然把表格的列状态留作租借,我该怎么做?

这就是我所做的

TRIGGER `tguDelete` AFTER DELETE ON `locations` FOR EACH ROW UPDATE movies SET situation = 'available' WHERE code_location = OLD.code_location

我想发布表格的图片,但我是论坛的新手 请帮帮我!

我使用phpmyadmin,我是mysql的新手

1 个答案:

答案 0 :(得分:1)

我认为您的触发器定义需要一些工作。例如 - 您要声明“trigger function”应该在AFTER表上执行DELETE locations次操作。这就是你如何做到的:

DROP TRIGGER IF EXISTS `tguDelete`;
DELIMITER $$
CREATE TRIGGER `tguDelete` AFTER DELETE ON `locations` 
FOR EACH ROW 
-- condition for rows for which the trigger would fire WHEN (OLD.code_location <> 0)
-- DECLARE
   -- if you had things you wanted to declare
BEGIN
   -- here you do the updating of the movies table:
   UPDATE movies SET situation = 'available' WHERE code_location = OLD.code_location;
END;$$
DELIMITER ;

如果您不需要DELIMITERS(即:PHPMyAdmin),请跳过它们,例如

DROP TRIGGER IF EXISTS `tguDelete`;
CREATE TRIGGER `tguDelete` AFTER DELETE ON `locations` 
FOR EACH ROW 
-- condition for rows for which the trigger would fire WHEN (OLD.code_location <> 0)
-- DECLARE
   -- if you had things you wanted to declare
BEGIN
   -- here you do the updating of the movies table:
   UPDATE movies SET situation = 'available' WHERE code_location = OLD.code_location;
END;