I have a relational table containing a foreign key in which there is no “on delete cascade” property set. Now I wanna delete a particular record but I am unable to do it!
When I try to delete a record from the referenced relation, It gives error “The delete statement conflicted with the foreign key constraint.”
When I try to delete a record from the referencing relation, It gives the same error.
Even I cannot change the database schema now. Any way out?
Update:
The relational Schema
Customer(c_id,c_name);
Products(p_id,p_name,p_cost);
purchases(p_id references Products,c_id references Customr);
I wanna delete a tuple from the purchases relation.
Update : The delete statement
The table already contains the following data :
c_id p_id
1 4
1 3
1 2
1 1
2 3
1 4(Notice duplicate tuple)
Now I wanna delete the record just above this line. i.e. the duplicate record.
I just right-clicked on the tuple shown in the table-view in the management studio and hit the delete key. It gived error.
UPDATE
I used
delete from Purchases where c_id=1 and p_id=4
It worked All Fine!!!
Initially I used to delete by selecting the record in the table-view and pressing the delete key. Now it worked. Can anyone Please explain me whatwas the difference?
You were probably using the Edit top X records interface in SQL Server Management Studio to delete the record. This functionality requires you to have a primary key defined on the table, since it needs to be able to uniquely identify the row you are trying to delete. It cannot delete the row from the table directly, all it does is construct the SQL in the background for you. Do you have a Primary Key defined on the table?