I have two tables, TableA and TableB.
TableB holds a copy of some records in TableA. TableB is read only.
TableA is live--rows are added, deleted, and updated regularly.
I need to write a script to see if rows from TableA which correspond to rows that exist in TableB (by corresponding ID field) have been modified, and if they have, I need to copy the new version of the row from TableA to TableB.
My first guess was to do some sort of LEFT JOIN WHERE NULLs existed after comparing each column for exact match. Ugly.
My second guess was to do:
INSERT INTO TableB ([cols])
SELECT * FROM TableA WHERE NOT EXISTS (SELECT * FROM TableB WHERE col1=TableA.col1, col2=TableA.col2, etc.).
These feel like really dirty solutions.
What should I do? Thanks a bunch.
TableB holds a copy of some records in TableA. TableB is read only.
TableA is live--rows are added, deleted, and updated regularly.
I need to write a script to see if rows from TableA which correspond to rows that exist in TableB (by corresponding ID field) have been modified, and if they have, I need to copy the new version of the row from TableA to TableB.
My first guess was to do some sort of LEFT JOIN WHERE NULLs existed after comparing each column for exact match. Ugly.
My second guess was to do:
INSERT INTO TableB ([cols])
SELECT * FROM TableA WHERE NOT EXISTS (SELECT * FROM TableB WHERE col1=TableA.col1, col2=TableA.col2, etc.).
These feel like really dirty solutions.
What should I do? Thanks a bunch.