如何使用sql server 2008 R2将数据库从现有数据库sql脚本复制到新数据库sql脚本?

时间:2021-02-09 08:26:39

i need sql script for copy database with data in sql server 2008 r2.I tried the below script but not working in sql server 2008.

我需要sql脚本用于复制数据库与sql server 2008 r2中的数据。我尝试了下面的脚本,但没有在sql server 2008中工作。

DBCC CLONEDATABASE ('MyDatabase', 'MyDatabase_Copy')

1 个解决方案

#1


0  

If you want to make a copy of the full database to another one you can make a full backup of the existing one and restore it as another database.

如果要将完整数据库的副本复制到另一个数据库,则可以对现有数据库进行完整备份,并将其还原为另一个数据库。

To perform a backup you can do doing something like this:

要执行备份,您可以执行以下操作:

BACKUP DATABASE MyDatabase TO DISK='C:\Backup directory\MyDatabase.bak'
  WITH INIT, FORMAT, SKIP

Then you restore that backup in the destination database (either overwriting an existing database or creating a new one):

然后在目标数据库中还原该备份(覆盖现有数据库或创建新数据库):

RESTORE DATABASE MyDatabase_Copy FROM DISK='C:\Backup directory\MyDatabase.bak'
  WITH REPLACE

If the destination database already exists you could need to use the MOVE option in the restore step (or perform a DROP DATABASE MyDatabase_Copy before restoring).

如果目标数据库已存在,则可能需要在还原步骤中使用MOVE选项(或在还原之前执行DROP DATABASE MyDatabase_Copy)。

#1


0  

If you want to make a copy of the full database to another one you can make a full backup of the existing one and restore it as another database.

如果要将完整数据库的副本复制到另一个数据库,则可以对现有数据库进行完整备份,并将其还原为另一个数据库。

To perform a backup you can do doing something like this:

要执行备份,您可以执行以下操作:

BACKUP DATABASE MyDatabase TO DISK='C:\Backup directory\MyDatabase.bak'
  WITH INIT, FORMAT, SKIP

Then you restore that backup in the destination database (either overwriting an existing database or creating a new one):

然后在目标数据库中还原该备份(覆盖现有数据库或创建新数据库):

RESTORE DATABASE MyDatabase_Copy FROM DISK='C:\Backup directory\MyDatabase.bak'
  WITH REPLACE

If the destination database already exists you could need to use the MOVE option in the restore step (or perform a DROP DATABASE MyDatabase_Copy before restoring).

如果目标数据库已存在,则可能需要在还原步骤中使用MOVE选项(或在还原之前执行DROP DATABASE MyDatabase_Copy)。