删除前获取字段值

发布于 2024-11-01 13:19:11 字数 159 浏览 3 评论 0原文

我有两个表类别(层次结构)和附件,它们之间有关系。

delete  from category where lft between @left and @right; 

我想从与这些类别相关的附件中删除!

我应该怎么办?

I have two table categories ( hierarchical structure ) and attachment that have relations together.

delete  from category where lft between @left and @right; 

and I want to delete from attachment which is related by those category !

What should I do?

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

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

发布评论

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

评论(2

故人的歌 2024-11-08 13:19:11

尝试:

delete c,a category c 
 join attachment a on c.id=a.category_id 
 where c.lft between @left and @right

Try:

delete c,a category c 
 join attachment a on c.id=a.category_id 
 where c.lft between @left and @right
瞎闹 2024-11-08 13:19:11

我建议在 InnoDB MySQl 和外国中使用 FOREIGH KEYS键约束并为关联类别和附件表的键定义 ON DELETE - CASCADE 选项。

第二个只是从附件中删除,其中category_id BETWEEN @left AND @right;

I would suggest using FOREIGH KEYS with InnoDB MySQl and Foreign key constraints and define ON DELETE - CASCADE option for the key that relates categories and attachment tables.

Second one is just DELETE FROM attachments WHERE category_id BETWEEEN @left AND @right;

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