日期:2014-05-19  浏览次数:20570 次

如何追加表里某一时间后的记录到另一个数据库的表
数据库a有表a_table,数据库b有表b_table。两个表的结构相同,但记录相同。现在想要把b_table中有而a_table中没有的某一个时间段以后的记录追加到a_table中,但不删除a_table原来的记录,该如何实现呢?

------解决方案--------------------
INSERT INTO [a].[a_table] select * from [b].[a_table] where id not in (select id from [a].[a_table])
------解决方案--------------------
insert into b..b_table
select * from a..a_table a
where not exists (select 1 from b..tble b where a.时间列 <b.时间列)
------解决方案--------------------
insert into b..b_table
select * from a..a_table a
where not exists (select 1 from b..tble b where a.时间列 <b.时间列)