[Solved] Move address data into separate table

David Asks: Move address data into separate table
Currently address information is stored directly in the OrderHeader and Customer tables. I would like to create a separate Address table and replace the current address information with a reference to the primary key of that table (AddressId).

The database already contains data (thousands of rows) and I can’t seem to figure out how to do this. I only figured out how to transfer the data over into the address table with the code below.

INSERT INTO Address (Address, City, State, ZipCode, AddressType)

SELECT Customer.Address,Customer.City,Customer.State,Customer.ZipCode,'Home' ASAddressType

FROM Customer


SELECT OrderHeader.ShipAddress, OrderHeader.ShipCity, OrderHeader.ShipState, OrderHeader.ZipCode, 'Home' AS AddressType

FROM OrderHeader;

What I have tried

Starting Schema

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.