I followed how to execute delete from: How to Delete using INNER JOIN with SQL Server?
The data I want to delete:
select * from com.Address a
inner join com.Contact as c on c.AddressId = a.AddressId
inner join cqt.CQMTrainer as t on t.ContactId = c.ContactId
select from com.Contact c
inner join cqt.CQMTrainer as t on t.ContactId = c.ContactId
Here is the delete I am trying to execute:
delete a from com.Address a
inner join com.Contact as c on c.AddressId = a.AddressId
inner join cqt.CQMTrainer as t on t.ContactId = c.ContactId
delete c from com.Contact c
inner join cqt.CQMTrainer as t on t.ContactId = c.ContactId
However, once I execute them I got some foreign key error:
The DELETE statement conflicted with the REFERENCE constraint "FK_com.Contact_com.Address_AddressId". The conflict occurred in database "", table "com.Contact", column 'AddressId'.
What am I following incorrectly? I even tried adding begin transaction
and commit transaction
.