多表关联,存在多个外键,级联删除
需要先取消外键约束,才能删除对应的表。删除完后,将外键约束设置上!! 记得删除时开启事务!
Code
-- 开启事务
START TRANSACTION;
-- 取消外键约束 才能删除表
SET foreign_key_checks = 0;
-- 删除航段
delete os from order_itinerary oi left join flight_order f on f.id = oi.order_id left join order_segment os on os.itinerary_id = oi.id WHERE f.cid = "8000yiEterm"
-- 删除行程
delete oi FROM flight_order f LEFT JOIN order_itinerary oi ON f.id = oi.order_id WHERE f.cid = "8000yiEterm"
-- 删除乘客
delete op FROM flight_order f LEFT JOIN order_passenger op ON f.id = op.order_id WHERE f.cid = "8000yiEterm"
-- 删除报表
DELETE ort FROM flight_order f LEFT JOIN order_report ort ON f.id = ort.order_id WHERE f.cid = "8000yiEterm";
-- 最后删除订单
DELETE f FROM flight_order f WHERE f.cid = "8000yiEterm";
-- 设置外键约束
SET foreign_key_checks = 1;
-- 提交事务
COMMIT;