How to DO MYSQL TRIGGER FOR DELETE Entry Before UPDATE
I have an Two table, main table is "Invoice" and sub table is "Invoice_split". Before update on the "Invoice" table I want to delete the related data on the sub table "Invoice_split" for that I have written the below query But it's not working.
"DELIMITER $$
CREATE TRIGGER开发者_如何学Python before_invoice_update
BEFORE UPDATE ON mac_invoice FOR EACH ROW
BEGIN
DELETE FROM mac_invoice_split WHERE OLD.invoice_id = id;
END$$
DELIMITER ;"
id => "Invoice" table primary key
invoice_id =>foreign key of "Invoice" in "Invoice_split" table
you should try this
WHERE OLD.id = invoice_id;
精彩评论