jeudi 29 novembre 2018

MySQL call function and procedure from a trigger

I made a function and procedure successfully, however when I try to call them from my trigger I get errors I don't know how to fix.. Can someone please help me :)

My function and procedure:

CREATE FUNCTION IsInBooking(id INT) RETURNS BOOLEAN BEGIN RETURN EXISTS(SELECT Customer_ID FROM booking WHERE Customer_ID = id); END

CREATE PROCEDURE DeleteRowFromBooking(IN id INT) BEGIN DELETE FROM booking WHERE Customer_ID = id; END

My trigger with error:

CREATE TRIGGER CustomerChargeback FOR EACH ROW BEGIN IF (CALL IsInBooking(Customer_ID)) THEN CALL DeleteRowFromBooking(Customer_ID) END IF; END

Basically what I want to do, is to delete any row with the same Customer_ID in the booking table if the row with the corresponding ID in the payment table is deleted.

Thanks so much!!!

Aucun commentaire:

Enregistrer un commentaire