我有两个表类别(层次结构)和附件,它们之间有关系。
delete from category where lft between @left and @right;
和我想从附件中删除,这是由这些类别相关的!
我该怎么办?
尝试:
delete c,a category c
join attachment a on c.id=a.category_id
where c.lft between @left and @right
我建议在InnoDB MySQl和外键约束下使用Foreign key,并为关联类别和附件表的键定义ON DELETE - CASCADE选项。
第二个就是DELETE FROM attachments WHERE category_id BETWEEEN @left AND @right;