开发者

Get field value before delete it

I have two table categories ( hierarchical structure ) and attachment that have relations togeth开发者_如何学Cer.

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?


Try:

delete c,a category c 
 join attachment a on c.id=a.category_id 
 where c.lft 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;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜