How to delete rows in tables that contain foreign keys to other tables

前端 未结 5 1384
借酒劲吻你
借酒劲吻你 2020-12-05 00:07

Suppose there is a main table containing a primary key and there is another table which contains a foreign key to this main table. So if we delete the row of main table it w

5条回答
  •  天命终不由人
    2020-12-05 00:26

    From your question, I think it is safe to assume you have CASCADING DELETES turned on.
    All that is needed in that case is

    DELETE FROM MainTable
    WHERE PrimaryKey = ???
    

    You database engine will take care of deleting the corresponding referencing records.

提交回复
热议问题