从同一服务器上的另一个数据库的备份中创建新的数据库?[英] Creating new database from a backup of another Database on the same server?

本文是小编为大家收集整理的关于从同一服务器上的另一个数据库的备份中创建新的数据库?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在尝试从同一服务器上的数据库的旧备份创建一个新数据库. 使用 SQL Server Management Studio 并尝试从备份还原到新DB时,我会得到此错误

System.Data.SqlClient.SqlError: The backup set holds a backup of a database 
other than the existing 'test' database. (Microsoft.SqlServer.Smo)

谷歌搜索后,我发现了这件代码

    RESTORE DATABASE myDB

 FROM DISK = 'C:\myDB.bak'

 WITH MOVE 'myDB_Data' TO 'C:\DATA\myDB.mdf',

MOVE 'myDB_Log' TO 'C:\DATA\myDB_log.mdf'
GO

我想知道移动语句会弄乱备份来自该服务器上的数据库吗?

谢谢,所有的帮助.

推荐答案

我应该做什么:

  • 单击"还原数据库..." float菜单,右图单击SQL Server Management Studio上的"数据库"节点.
  • 用数据库填充向导和新名称.
  • 重要如果数据库仍然存在,则将"恢复为"文件"选项卡中的"文件名"更改为"避免使用"的文件,无法覆盖"错误消息".

我做什么

idk为什么我更喜欢这样做:

  • 我用我喜欢的参数创建一个空白的目标数据库.
  • 然后,在" SQL Server Management Studio"还原向导中,我寻找覆盖目标数据库的选项.它在"选项"选项卡中,称为'覆盖现有数据库(带有替换)'.检查它.
  • 记住在"文件"页面中选择目标文件.

您可以在向导的左侧更改"选项卡"(常规,文件,选项)

其他推荐答案

甚至可以完全不创建空白数据库的情况.

在SQL Server Management Studio中,右键单击数据库,然后选择还原数据库...

在Restore数据库对话框中,按照普通的方式选择源数据库或设备. 一旦选择了源数据库,SSM将根据数据库的原始名称填充目标数据库名称.

然后可以更改数据库的名称,然后输入新的目标数据库名称.

使用这种方法,您甚至不需要转到选项选项卡,然后单击"现有数据库"选项.

另外,数据库文件将以您的新数据库名称始终命名,如果需要,您仍然可以选择更改文件名.

其他推荐答案

检查写入数据库的选项对我有用:)

在此处输入图像说明

本文地址:https://www.itbaoku.cn/post/597572.html

问题描述

I am trying to create a new database from an old backup of database on the same server. When using SQL server management studio and trying to restore to the new DB from the backup I get this error

System.Data.SqlClient.SqlError: The backup set holds a backup of a database 
other than the existing 'test' database. (Microsoft.SqlServer.Smo)

after googling around I found this piece of code

    RESTORE DATABASE myDB

 FROM DISK = 'C:\myDB.bak'

 WITH MOVE 'myDB_Data' TO 'C:\DATA\myDB.mdf',

MOVE 'myDB_Log' TO 'C:\DATA\myDB_log.mdf'
GO

I was wondering will the move statements mess with the database that the backup came from on that server?

Thanks, all help appreciated.

推荐答案

What I should to do:

  • Click on 'Restore Database ...' float menu that appears right clicking the "Databases" node on SQL Server Management Studio.
  • Fill wizard with the database to restore and the new name.
  • Important If database still exists change the "Restore As" file names in the "Files" tab to avoid "files already in use, cannot overwrite" error message.

What I do

IDk why I prefer to do this:

  • I create a blank target database with my favorite params.
  • Then, in "SQL Server Management Studio" restore wizard, I look for the option to overwrite target database. It is in the 'Options' tab and is called 'Overwrite the existing database (WITH REPLACE)'. Check it.
  • Remember to select target files in 'Files' page.

You can change 'tabs' at left side of the wizard (General, Files, Options)

其他推荐答案

It's even possible to restore without creating a blank database at all.

In Sql Server Management Studio, right click on Databases and select Restore Database... enter image description here

In the Restore Database dialog, select the Source Database or Device as normal. Once the source database is selected, SSMS will populate the destination database name based on the original name of the database.

It's then possible to change the name of the database and enter a new destination database name.

enter image description here

With this approach, you don't even need to go to the Options tab and click the "Overwrite the existing database" option.

Also, the database files will be named consistently with your new database name and you still have the option to change file names if you want.

其他推荐答案

Checking the Options Over Write Database worked for me :)

enter image description here