How To Delete Rows From Tow Tables When They Have Foreign Keys To Each Other



TODO:

You have table A, and Table B.  Table A has a foreign key to table B, and table B has a foreign key to table A.  You need to delete data from table A, but cannot because of the foreign key on Table B.

 

SOLUTION:

ALTER TABLE employee NOCHECK CONSTRAINT ALL
delete employee where id=100
ALTER TABLE employee WITH CHECK CHECK CONSTRAINT ALL


NOTES:

This will allow you to delete data when there arecircular foreign keys.