2

Possible Duplicate:
I got error “The DELETE statement conflicted with the REFERENCE constraint”

I am receiving the error

The DELETE statement conflicted with the REFERENCE constraint fk

Is there away to automatically delete the row that is causing this reference conflict such as setting a property or such. To avoid first deleting the child and then going back and deleting the original row you wanted to delete?

Community
  • 1
  • 1
Marquis Blount
  • 7,585
  • 8
  • 43
  • 67
  • You need to set the foreign key's delete option to CASCADE on delete – user710502 Mar 10 '12 at 23:25
  • SQL-Server: http://msdn.microsoft.com/en-us/library/ms186973.aspx and here(with SSMS): http://www.mssqltips.com/sqlservertip/2365/sql-server-foreign-key-update-and-delete-rules/ – Tim Schmelter Mar 10 '12 at 23:26

3 Answers3

0

Turn on delete cascade to your table and the referencing row will be deleted automatically too.

juergen d
  • 201,996
  • 37
  • 293
  • 362
0

When you create your table, specify ON DELETE CASCADE.

This sets up the delete action for the table to also delete referencing rows, if it is the parent.

See http://msdn.microsoft.com/en-us/library/ms174979.aspx.

womp
  • 115,835
  • 26
  • 236
  • 269
0

Delete the key to key table, the relation table first before deleting the original primary key record.

iefpw
  • 6,816
  • 15
  • 55
  • 79