-- 1. remove rows in T2 that are not in T1 delete T2 where not exists ( select 1 from T1 where T1.Ka = T2.Ka and T1.Kb = T2.Kb and ... -- The where clause can be generated by something like: -- join(' and ', map { "T1.$_ = T2.$_" } @key_col_names) ) -- 2. synchronize rows that exist in both update T1 set T1.Va = T2.Va, T1.Vb = T2.Vb, ... from T1, T2 where T1.Ka = T2.Ka and T1.Kb = T2.Kb and ... and ((T1.Va != T2.Va) or (T1.Vb != T2.Vb) ...) -- Check that your platform supports a "from" clause -- in update statements. -- You can actually omit the "value" test; it just eliminates -- unnecessary data movement. Beware that nullable columns -- need more complicated tests. -- 3. insert new rows insert T2 (Ka, Kb, ..., Va, Vb, ...) select Ka, Kb, ..., Va, Vb, ... from T1 where not exists ( select 1 from T2 where T1.Ka = T2.Ka and T1.Kb = T2.Kb and ... )