If I have two tables with identical column definitions, I could do the following:
DELETE FROM table_2 WHERE pkey NOT IN (select pkey from table_1);
There are similar statements to insert into B anything not already in it but in A, and to update any rows with matching pks in A.
Can all of these statements be be performed at once with MERGE INTO?
MERGE INTO table_1 b
USING table_2 a
ON b.pkey = a.pkey
WHEN MATCHED
THEN UPDATE SET col1 = a.col1, col2 = a.col2 ...
WHEN NOT MATCHED
THEN INSERT (col1, col2) values (a.col1, a.col2)
Is there any way of determining that the destination has a row not matched in the source, such that I could then do the DELETE? If there's a clever way to manipulate the ON clause, I can't see it or think of how to search for it. The documentation doesn't make this very clear.