我有两个表,主表是“Invoice”,子表是“Invoice_split”。 在更新“发票”表之前,我想删除子表“Invoice_split”上的相关数据,因为我已经写了下面的查询但是它没有用。
"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
答案 0 :(得分:1)
你应该试试这个
WHERE OLD.id = invoice_id;