surezram
surezram

Reputation: 393

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 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

Upvotes: 0

Views: 753

Answers (1)

Nishant
Nishant

Reputation: 55866

you should try this

  WHERE OLD.id = invoice_id;

Upvotes: 1

Related Questions