This question already has answers here:
I got error "The DELETE statement conflicted with the REFERENCE constraint" (5 answers)
Closed yesterday.
Delete From Department_Master Where Active = 0
this is my Query When I try to delete some records where Active is 0 its getting me error The DELETE statement conflicted with the REFERENCE constraint "FK__Employee___Depar__29572725". The conflict occurred in database "abc", table "dbo.Employee_Details", column 'Department_Id'.The statement has been terminated. How to resolve
How to Solve this error
1条答案
按热度按时间06odsfpq1#
You can't just delete a parent record and leave orphan child records behind. Either you want the database to automatically delete related records or you don't. If you don't, you need to manually delete the related records first. If you do, you need to configure that relation and specify to cascade on delete. The alternative would be to update all the child records and change their parent first, then delete ethe old parent.