0
删除数据我有3个表MySQL的 - 如何从整个相关表
tbl_car
id | name
1 | toyota
tbl_brand
id | brand_name | **car_id** (one to many)
1 | brand1 | 1
2 | brand2 | 1
tbl_item
id | item_name | **brand_id** (one to many)
1 | brand1_item1 | 1
2 | brand1_item2 | 1
3 | brand2_item1 | 2
4 | brand2_item2 | 2
我想从tbl_car删除数据ID = 1,我尝试
DELETE tbl_car a LEFT JOIN tbl_brand b ON a.id = b.car_id LEFT JOIN tbl_item c ON b.id = c.brand_id WHERE a.id = 1
但它没有工作。我想要的是删除tbl_car id = 1和关系表中的全部数据.i感谢任何帮助,谢谢。
看后进入on删除外键 – Mihai
我使用CASCADE选项那个,但是我读了那么多文章告诉说ON DELETE CASCADE是个坏主意。像这样http://dba.stackexchange.com/questions/74627/difference-between-on-delete-cascade-on-update-cascade-in-mysql – plonknimbuzz
@plonknimbuzz不使用级联的原因与不使用级联相同在一个语句中使用多表删除。 –