gpt4 book ai didi

mysql - 我怎样才能通过验证来触发删除

转载 作者:行者123 更新时间:2023-11-29 11:14:43 24 4
gpt4 key购买 nike

我是论坛新手,我有以下问题,我想在删除租赁表位置后进入表电影并使列情况变得可用,但如果我有电影的代码在另一个寄存器的表位置中,我仍然将表膜的列状态保留为租用状态,我该怎么做?

这就是我所做的

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

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

我使用phpmyadmin,而且我是mysql新手

最佳答案

我认为您的触发器定义需要一些工作。例如 - 您想要声明“触发函数”,该函数应在位置上的DELETE操作之后执行> 表。您可以这样做:

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 ;

如果您不需要分隔符(即: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;

关于mysql - 我怎样才能通过验证来触发删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39944329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com