[轉]如何拷貝一個 SQL Server 的表


這篇短文將介紹幾種拷貝 SQL Server 表的方法。第一種方式是最簡單的在同一個數據庫里將表拷貝到另外一個表。你需要記住的是,拷貝表的時候並不會拷貝表的約束和索引。下面是代碼模板和簡單的使用方法:

1 select * into <destination table> from <source table>
2  
3 Example:
4 Select * into employee_backup from employee

我們也可以只拷貝某些字段:

1 select col1, col2, col3 into <destination table>
2 from <source table>
3  
4 Example:
5 Select empId, empFirstName, empLastName, emgAge into employee_backup
6 from employee

下面的方法僅拷貝表結構,不包含數據:

1 select * into <destination table> from <source table> where 1 = 2
2  
3 Example:
4 select * into employee_backup from employee where 1=2

而下面方法可將表拷貝到另外的 SQL Server 服務器上:

select * into <destination database.dbo.destination table>
from <source database.dbo.source table>
 
Example:
select * into Mydatabase2.dbo.employee_backup
from mydatabase1.dbo.employee

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM