patternsqlMajor
The DELETE statement conflicted with the REFERENCE constraint
Viewed 0 times
referencethedeletestatementwithconstraintconflicted
Problem
I'm trying to delete all users but getting the error:
The query:
Seems I need to use
Msg 547, Level 16, State 0, Line 1
The DELETE statement conflicted with the REFERENCE constraint "FK_M02ArticlePersons_M06Persons". The conflict occurred in database "workdemo.no", table "dbo.M02ArticlePersons", column 'M06PersonId'.
The statement has been terminated.The query:
DELETE FROM [workdemo.no].[dbo].[M06Persons]
WHERE ID > '13'
GOSeems I need to use
on delete cascade; but I'm stuck.Solution
You don't need to use the on delete cascade. Somebody (the schema design author) had made sure you cannot delete a person that is still referenced by an article. It succeeded, you were just trying to do this and was blocked, kudos to the designer.
Now go and talk with that somebody that designed the schema and knows the constraints and ask him how to properly delete the records you're trying to delete, in the correct order and taking the proper precautions to keep the database consistent.
Now go and talk with that somebody that designed the schema and knows the constraints and ask him how to properly delete the records you're trying to delete, in the correct order and taking the proper precautions to keep the database consistent.
Context
StackExchange Database Administrators Q#39229, answer score: 22
Revisions (0)
No revisions yet.