如何在更新之前触发 MYSQL 删除条目
我有一个两个表,主表是“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该试试这个
you should try this