20000条数据是比较小的数据量了。
如果一次性处理:
Insert into a
select * from b where b.Id not in (select Id from a )
如果是频繁处理,可以考虑用触发器,给个简单例子:
ALTER TRIGGER Tri_a_b_ForInsertOrUpdate
ON b
FOR Insert,Update
AS
BEGIN TRAN
insert into a
select * from b where ID in (select ID from inserted)
IF (@@ERROR <> 0)
Begin
ROLLBACK TRAN
RAISERROR ('同步数据时出错!', 16, 1)
Return
End
COMMIT TRAN
楼上应该是最简单的了。