I need to refactor a Company table so that the address information is moved into a dedicated Address table.
So I figure I need to do something like this to create the new address records.
INSERT INTO address (city, country, ...)
SELECT city,country, ... FROM company
ALTER TABLE address ADD company_id INTEGER
INSERT INTO address (city,country,company_id)
SELECT city,country,id from company
UPDATE company c set c.address_id = (select a.id from address a where a.company_id = c.id)
ALTER TABLE address DROP COLUMN company_id;
You could use a
company_id in your
INSERT INTO address (company_id, city, country, ...) SELECT id, city, country, ... FROM company
Then there is no need to add any
address_id to the