MrValvis
MrValvis

Reputation: 137

SQL Server throws an error "The DELETE statement conflicted with the REFERENCE constraint" even when using NOCHECK CONSTRAINT

I am using a small application and every SQL query that writes or read from the database works fine except the delete. I can't understand what I am doing wrong since I deactivated all constraints.

I am using this query but I keep getting the error (only the DELETE FROM [dbo].[Orders] is causing this error, the history deletion works fine)

The DELETE statement conflicted with the REFERENCE constraint "FK_Order_Details".

Here is the SQL query :

ALTER TABLE [dbo].[Orders] NOCHECK CONSTRAINT all;

DELETE FROM [dbo].[Orders] 
WHERE ([OrderID] = @OrderID);

DELETE FROM [dbo].[History] 
WHERE ([OrderID] = @OrderID);

ALTER TABLE [dbo].[Orders] CHECK CONSTRAINT all;

Thanks in advance for any help!

Upvotes: 0

Views: 105

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89016

The constraint FK_Order_Details is on another table. Probably one called "OrderDetails".

Upvotes: 4

Related Questions