在不使用备份的情况下克隆SQL Server数据库

时间:2018-04-04 14:22:29

标签: sql-server

有没有办法用数据创建一个数据库的副本但不使用备份文件?

我尝试过DBCC CLONEDATABASE但没有复制数据。我正在使用SQL Server 2014

我想在不使用任何向导的情况下使用脚本来完成。

1 个答案:

答案 0 :(得分:1)

1) Create your Database. 
2) Generate the Schema Scripts of the Source Database
   2.1) Right Click your source DatabseName > Generate Scripts.
   2.2) Select "Script specific database objects", Select all Checked-boxes
   2.3) Select "Save to new query window"
   2.4) You will now see the scripts to create all the schemas, Where it say USE 
        [DatabseName] change that to your new Database.
3) Now for the Data, you do the same above but with a few changes. 
   You could do the data and Schema together, but I prefer to do it individually,
   especially if you have large databases.   
3.1) Right Click your source DatabseName > Generate Scripts. 
3.2) Click on "Advanced"
3.3) Scroll down to "Types of data to script" and select "Data Only"
3.4) Select "Save to new query window"
3.5) You see all the data in a SQL script, again change the "USE [DatabseName]" 
     to your new Database.