SQL 複製表結構+數據

如果新表不存在
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...

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章