
sql 如何实现表的追加,即,将一个表里的数据添加到另外一张表里,两个表的结构是一样的。
2个回答
展开全部
可以这样
insert into table1 select * from table2 a where not exists(select * from table1 b where 主键关联)
insert into table1 select * from table2 a where not exists(select * from table1 b where 主键关联)
更多追问追答
追问
非常感谢,但是现在又有这样个问题,
对于自动增长的序号插入时怎么处理?
会报错“仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'sql_exam.dbo.t_student'中的标识列指定显式值。”
追答
那你要指定字段,如下
insert into table1(这里指定除自动增长外的字段) select 除自动增长外的字段 from table2 where ...
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询