Delete data with foreign key in SQL Server table

后端 未结 9 633
青春惊慌失措
青春惊慌失措 2020-12-12 20:32

I\'m going to delete data in an SQL Server table (parent) which has a relationship with another table (child).
I tried the basic Delete query. But it isn\'t working (and

9条回答
  •  醉话见心
    2020-12-12 21:32

    If you wish the delete to be automatic, you need to change your schema so that the foreign key constraint is ON DELETE CASCADE.

    For more information, see the MSDN page on Cascading Referential Integrity Constraints.

    ETA (after clarification from the poster): If you can't update the schema, you have to manually DELETE the affected child records first.

提交回复
热议问题