Delete rows from two tables in one query

后端 未结 5 964
[愿得一人]
[愿得一人] 2021-02-09 08:43

I have two tables: orders and orders_items. Both sharing the field orderID.

I want to delete all rows from both tables where orderID=500, but I need to do this in only o

5条回答
  •  暖寄归人
    2021-02-09 09:27

    That depends on your database engine, but basically what you need sounds like you want one table referencing the other using a FOREIGN KEY with ON DELETE CASCADE option and then removal from the parent table will automatically remove corresponding rows from dependent tables.

提交回复
热议问题