Delete SQL record with dependency

Asked

Viewed 878 times

0

Good afternoon.

I wonder how to delete records from a table containing foreign key.

I would not like to delete the children records (to keep the history).

I always get a message warning that there are dependencies when trying to update a parent record.

  • That’s exactly what it was! Unfortunately I couldn’t implement the null set through Workbench... What I did to get around the problem was to create a new column in the Father table to identify the records that were deleted. This way the foreign key was kept. I even thought of something like a clone table, but I wouldn’t know how to implement without studying a little r. Thanks for the Help!!!

1 answer

2

When creating the foreign key it is possible to define its behavior when there is a DELETE:

NO ACTION: Delete parent record is not allowed. An error message is generated.

CASCADE: The entire line of the child record is deleted.

SET NULL: the child records are maintained, but the value in the column holding the foreign key is placed on the NULL.

SET DEFAULT: puts a defined default value.

If none fits, the solution can go through removing the foreign key or maintaining a clone table, for history, no foreign key.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.