删除前获取字段值
我有两个表类别(层次结构)和附件,它们之间有关系。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
Try:
我建议在 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;