SQLServer复制表及数据的两种方法

1、新表不存在(即复制数据的同时创建与旧表相同结构的新表):

 
  select [col1,col2,col3...] into new_table from old_table where 1=1 
 
2、新表已存在,从旧表从插入选择的数据(注意:表的[主键]不要复制,因为具有唯一性,否则:Sql Server提示“当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'xxxxxx' 中的标识列插入显式值”)
 
 insert into table1(col1,col2,col3,...)
 select [col1,col2,col3...] from table2
 
3、将A表查询到的数据更新到B表中
update A set A.W_Name =B.W_Name from A,B where A.ID = B.ID
posted @ 2023-02-17 11:52  瘦子梅西尔  阅读(701)  评论(0编辑  收藏  举报