I have a table where some of the referenced datastores
have been deleted and their foreign key reference nulled. I need to insert a fresh datastore
and set the foreign key in the reference table.
All of the IDs are UUIDs
and my pseudo query looks like this but does not work:
UPDATE `rcachievements_player_achievements`
SET data_id = (INSERT INTO `rcachievements_datastore` (data) VALUES ('{"count":0}'))
WHERE data_id is null
Is there any way to insert the datastore
and then set the id
in the data_id
field for every row that has a missing data store?
2
Answers
I ended up doing it with a FOR LOOP, like the following:
You have to do it as multiple queries. First insert the new row into
rcachievements_datastore
, then update all the referencing rows.