I have two tables, object and object_data, with an object referencing object_data by foreign key (the ratio is 1: 1). For a set of objects, I need to nullify their object_data links and delete the corresponding object_data lines, for example:
DELETE FROM object_data WHERE id IN ( SELECT object_data_id FROM object WHERE ... ); UPDATE object SET object_data_id = NULL WHERE ...;
The problem is that the foreign key constraint prevents the removal of object_data strings that still reference the object.
My current solution reads the SELECT results into a list, then nullifies the foreign keys, and then deletes the object_data strings in batches of a reasonable size using the IN statement. Is there a better solution? Adding a column referencing an object_data object to an object is not an option.
laurt source share