Last active
April 14, 2022 11:44
-
-
Save garystafford/0a85ee5c3c7eeceb4a4ef5534220c782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- wrap in transaction | |
BEGIN; | |
-- copy only customer addresses to new customers.address table | |
INSERT INTO customers.address | |
SELECT * | |
FROM common.address | |
WHERE common.address.address_id IN ( | |
SELECT DISTINCT address_id | |
FROM customers.customer | |
); | |
-- copy only staff addresses to new staff.address table | |
INSERT INTO staff.address | |
SELECT COUNT(*) | |
FROM common.address | |
WHERE common.address.address_id IN ( | |
SELECT DISTINCT address_id | |
FROM staff.staff | |
); | |
-- copy only store addresses to new stores.address table | |
INSERT INTO stores.address | |
SELECT * | |
FROM common.address | |
WHERE common.address.address_id IN ( | |
SELECT DISTINCT address_id | |
FROM stores.store | |
); | |
-- check for extraneous data in common.address before deleting | |
SELECT * | |
FROM common.address | |
WHERE common.address.address_id NOT IN | |
(SELECT DISTINCT address_id FROM customers.customer) | |
AND common.address.address_id NOT IN | |
(SELECT DISTINCT address_id FROM staff.staff) | |
AND common.address.address_id NOT IN | |
(SELECT DISTINCT address_id FROM stores.store); | |
COMMIT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment