How to update foreign keys while inserting rows?
I have two tables with the following layout ...
------------- -------------------------
| Master | | History |
------------- -------------------------
| id | name | | id | name | master_id |
------------- -------------------------
The history table contains rows where the master_id is NULL. Those I copy
into the master table.
INSERT master (name)
SELECT name
FROM histories h
WHERE h.master_id = NULL
How can I update the master_id in the history table with the id of the
associated object in the master table? This update should happen in the
same step as the insertion is made. I use MySQL if this is of interest.
No comments:
Post a Comment