oktell

这篇短文将介绍几种拷贝 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

 

分类:

技术点:

相关文章:

  • 2021-04-23
  • 2021-11-23
  • 2021-07-28
  • 2021-12-06
  • 2022-01-27
  • 2021-08-05
  • 2021-07-06
  • 2021-04-17
猜你喜欢
  • 2021-05-14
  • 2018-10-18
  • 2021-09-06
  • 2021-09-28
  • 2021-09-13
  • 2021-10-25
  • 2020-01-13
相关资源
相似解决方案