如果新表不存在
select * into newtable from oldtable
如果存在
insert into newtable select * from oldtable ---表结构一致
insert into newtable(列名1,列名2,.....) select 列名1,列名2....from oldtable --表结构不一致
--跨数据库
--复制结构+数据
select * into 数据库名.dbo.新表名 from 数据库名.dbo.原表名
--只复制结构
select * into 数据库名.dbo.新表名 from 数据库名.dbo.原表名 where 1=0
--复制到临时表
select * into #temptablename from 数据库名.dbo.原表名 where 1=0
--后面的where 1=0 只要不成立就行了,管它是1=2,还是1000=1001...
150

被折叠的 条评论
为什么被折叠?



