2011-04-07 64 views
2

如何創建一個重複表中沒有任何數據如何創建一個重複表中沒有任何數據

舊錶名 - 學生

newtablename - student1

PLZ告訴我exat查詢

感謝, 丘吉爾..

+0

可能重複:HTTP://計算器.com/questions/4616707/sql-server-copy-full-table-definition – 2011-04-07 21:35:31

回答

5
SELECT TOP 0 * INTO student1 FROM student 
+1

缺點是它不會複製索引,PK,FK等。下面是如何複製完整的表結構:http:// dba.stackexchange.com/questions/18059/copy-c完整結構的表 – 2015-11-26 19:18:36

3
select * into student1 from student where 1=0 
+1

,但'student1'不包含索引,約束和其他東西,這是'學生'表模式的一部分。 – 2011-04-07 21:40:51

1

SELECT * 到student1 從學生那裏 1 = 2

這將讓你的欄目, 但索引和其他對象 需要腳本 與某種類型的數據庫工具。

0
create table newtable as select * from oldtable where clause 
+0

這不會幫助操作...它複製數據,也不會複製像自動增量 – NineCattoRules 2017-01-17 15:41:29

0

首先,你可以通過整個表複製:

select * into (your_table_name) from student 

複製整個表後,可以通過運行刪除數據:

truncate table (your_table_name); 
相關問題