
1、忽略表之间的关联关系
ALTER TABLE db2.dbo.table NOCHECK CONSTRAINT 关系名
2、--将没有重复的数据合并
insert into db2.dbo.table(field1,field2...) select field1,field2... from db1.dbo.table a where a.username not in (select username from db2.dbo.table)
3、将重复的数据写入临时表
select field1,field2... into 新的临时表 from db1.dbo.table a where a.username in (select username from db2.dbo.table)
要将两表合并,必须要有相同的字段和字段数据,ID主键自动增加无疑是最好的选择。所以,在两个表中,都应该有id主键自动增加的字段。
然后就是下面的sql语句执行了:
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)