我需要一个触发器,当我Fize hum插入表“reserve”时自动添加Table Room The Current State。
一个主要问题是我需要检查reserva.id E是否等于quarto.id。
我如何检查现场和通讯员的情况? 这是一些失败的尝试代码。
CREATE TRIGGER OcuparQuarto
AFTER UPDATE OF id ON reserva
FOR EACH ROW
BEGIN
UPDATE quarto
SET status='0'
WHERE id=NEW.id;
END;
或
Delimiter |
create trigger OcuparQuarto
after insert on reserva
for each ROW
UPDATE quarto
SET quarto.status = 0
FROM quarto
INNER JOIN reserva ON quarto.id = reserva.id
END;
|
delimiter ;
答案 0 :(得分:0)
begin
if(new.status = 0)然后更新quarto set status = 0,其中quarto.id = new.quarto_id;
elseif(new.status = 1)然后更新quarto set status = 1 where quarto.id = new.quarto_id;
elseif(new.status = 2)然后更新quarto set status = 0 where quarto.id = new.quarto_id;
elseif(new.status = 3)然后更新quarto set status = 1 where quarto.id = new.quarto_id;
结束如果;端
这个作品!谢谢!