insert into c values ( column1, column2 ) select a.column1,a.column2 ... from a where not exists (select 1 from b where b.column1 = a.column1 ...) union select (b.counmn1,b.column2 ...) from b where not exists (select 1 from a where b.column1 = a.column1 ...) 其中 exist where b.column1 = a.column1 ... 是所有列
你这里说‘数据库A 中的A表,与数据库B中的A表通过比较’,如果数据库A的A表是参照表不变的话,
你可以minus下A库A表与B库A表,出来的结果就是A库A表与B库A表不一致的数据,你把B库A表中相对应的数据删掉,然后把这部分数据插入到B库A表,
反之再执行一遍,就完成了数据一致
select (b.counmn1,b.column2 ...) from b where not exists (select 1 from a where b.column1 = a.column1 ...)
其中 exist where b.column1 = a.column1 ... 是所有列
A表必须要有唯一主键,如果没有则没办法比较;
如果数据库a的a表有数据而数据库b的a表没有,则认为是add数据,把数据库a的a表的该数据插入数据库b的a表;
如果数据库a的a表和数据库b的a表存在主键相同的数据,则比较其他字段(一般只比较重点的几个字段,不会所有字段都比较),如果两边其他字段的数据不一致,则认为是update数据,删除数据库b的a表该数据,把数据库a的a表的该数据插入数据库b的a表。
delete的数据其实也可以比较的,同理。