在删除之前获取字段值

时间:2011-04-14 15:34:00

标签: mysql fetch sql-delete

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

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

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

我该怎么办?

2 个答案:

答案 0 :(得分:1)

我建议在InnoDB MySQl and Foreign key constraints中使用FOREIGN KEYS,并为与类别和附件表相关的键定义ON DELETE - CASCADE选项。

第二个只是DELETE FROM attachments WHERE category_id BETWEEEN @left AND @right;

答案 1 :(得分:1)

尝试:

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