php - Delete duplicate rows in MySQL table but foreign key relationship exists? -


How do I delete duplicate rows from a MySQL table when a foreign key connection is already set up on those lines has gone.
Can duplicate somehow and merge updated foreign key with new value?

If the foreign key is on the delayed case , then by removing duplicate rows Also, dependent rows will be deleted, for example, if you have a table customer and a table command , and DELETE a foreign key like the optional table commands CASCADE Foreign Key Key Customer_ID references (ID), then by removing a customer, delete that customer's order too Interpretation will Similarly, if the foreign key went delete the SET NULL , the order will not be deleted, but they customer_id value will be set to zero.

If none of these are the desired behavior, then prepare a query that resolves foreign key conflicts by changing foreign key columns so that they reference the line you want to keep ( I.e., update all orders to refer to non-fake customers), then remove offensive rows.

Yet another option is to disable the foreign key check temporarily, but it will leave you from an incompatible database, so I do not recommend it.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -