The code below is not compiling by HeidiSQL in a MYSQL base
BEGIN
if NOT EXISTS (SELECT * FROM pedido_itens WHERE ID_PEDIDO = OLD.ID_pedido)
DELETE from pedido WHERE pedido.ID = pedido_itens.old.ID_PEDIDO;
END if;
END
I’m trying to create a trigger to remove from the "pedido" table when there are no more items in the "pedido_itens" table. But I can’t compile, I don’t understand where I’m going wrong. Thanks in advance for all help.
I’m new in the area.
2
Answers
I got it, had to change some details. But mostly the "then" was missing
with if statement you should use ‘then’,it is for what action you want to perform against your if.