如何在更新之前触发 MYSQL 删除条目

发布于 2024-10-18 06:53:57 字数 419 浏览 2 评论 0原文

我有一个两个表,主表是“Invoice”,子表是“Invoice_split”。 在更新“Invoice”表之前,我想删除子表“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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毅然前行 2024-10-25 06:53:57

你应该试试这个

  WHERE OLD.id = invoice_id;

you should try this

  WHERE OLD.id = invoice_id;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文