开发者

How to DO MYSQL TRIGGER FOR DELETE Entry Before UPDATE

开发者 https://www.devze.com 2023-02-12 06:18 出处:网络
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 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;
0

精彩评论

暂无评论...
验证码 换一张
取 消