【发布时间】:2018-06-25 03:30:52
【问题描述】:
鉴于这些架构
订单(订单号,已创建,状态) 产品(product_id,product_name) orders_products(order_number,product_id,quantity)
如果我想删除超过 N 天的订单,我还必须删除 orders_products 表中与这些订单相关的记录。
如何在单个查询中执行此操作,而不必检索每个 order_number,将它们存储在业务逻辑中,最后运行其他查询来清理映射表?
我没有FK
【问题讨论】:
-
在您的数据库结构中的数据透视表上使用
ON DELETE CASCADE,如@mentallurg 所述!!!
标签: mysql many-to-many