使用SQL Server Management Studio还原SQL数据库备份

We have previously covered a simple SQL database restore using the command line which is ideal for restoring backup files created on the same SQL Server installation, however if you are restoring a backup created on a different installation or simply prefer a point and click interface, using SQL Server Management Studio (or the Express edition) makes this task easy.

之前,我们已经介绍了使用命令行进行简单SQL数据库还原的方法,该方法非常适合还原在同一SQL Server安装上创建的备份文件,但是,如果要还原在其他安装上创建的备份,或者只是更喜欢单击界面,则使用SQL Server Management Studio(或Express版)使此任务变得容易。

Note: SQL Server experts might want to skip today’s lesson, as it’s aimed at beginners.

注意:SQL Server专家针对初学者,可能希望跳过今天的课程。

Before starting, you will need to copy the SQL backup file (typically has a .BAK extension) to a local hard drive on the destination SQL Server machine.

开始之前,您需要将SQL备份文件(通常具有.BAK扩展名)复制到目标SQL Server计算机上的本地硬盘驱动器上。

Open SQL Server Management Studio and login to the SQL Server you want to restore the database to. It is best to either login as a Windows Administrator or as the SQL ‘sa’ user.

打开SQL Server Management Studio,然后登录到要将数据库还原到SQL Server。 最好以Windows管理员或SQL“ sa”用户身份登录。

使用SQL Server Management Studio还原SQL数据库备份

Once logged in, right click on the Databases folder and select ‘Restore Database’.

登录后,右键单击“数据库”文件夹,然后选择“还原数据库”。

使用SQL Server Management Studio还原SQL数据库备份

Click the ellipses button next to ‘From device’ under the ‘Source for restore’ section.

单击“还原源”部分下“来自设备”旁边的省略号按钮。

使用SQL Server Management Studio还原SQL数据库备份

Set ‘File’ as the backup media and then click ‘Add’.

将“文件”设置为备份媒体,然后单击“添加”。

使用SQL Server Management Studio还原SQL数据库备份

Browse to the SQL backup (BAK) file you want to restore.

浏览到要还原SQL备份(BAK)文件。

使用SQL Server Management Studio还原SQL数据库备份
使用SQL Server Management Studio还原SQL数据库备份

In the Restore Database dialog, type or select the name of the database you want this backup restored to.

在“还原数据库”对话框中,键入或选择要将备份还原到的数据库的名称。

  • If you select an existing database, it will be replaced with the data from the backup.

    如果选择现有数据库,它将被备份中的数据替换。
  • If you type a database name which does not currently exist in your SQL Server installation, it will be created.

    如果键入您SQL Server安装中当前不存在的数据库名称,则会创建该数据库名称。

Next, select the restore point you want to use. Since a SQL backup file can hold multiple backups you may see more than one restore point listed.

接下来,选择要使用的还原点。 由于SQL备份文件可以保存多个备份,因此您可能会看到列出了多个还原点。

使用SQL Server Management Studio还原SQL数据库备份

At this point, enough information has been entered for the database to be restored. However, SQL backup files store information about where data files are copied so if there are any file system problems such as a the destination directory not existing or conflicting data file names an error will occur. These problems are common when restoring a backup created on a different SQL Server installation.

此时,已经输入了足够的信息来还原数据库。 但是,SQL备份文件存储有关数据文件复制位置的信息,因此,如果存在任何文件系统问题,例如目标目录不存在或数据文件名冲突,将发生错误。 还原在其他SQL Server安装上创建的备份时,这些问题很常见。

To review and change the file system settings, click the Options page on the left in the Restore Database dialog.

要查看和更改文件系统设置,请单击“还原数据库”对话框左侧的“选项”页面。

使用SQL Server Management Studio还原SQL数据库备份

On the options page, you will want to make sure the ‘Restore As’ column points to valid folder locations (you can change them as needed). The the files do not have to exist, however the folder path must exist. If the respective files do exist, SQL Server follows a simple set of rules:

在选项页面上,您将要确保“还原为”列指向有效的文件夹位置(您可以根据需要更改它们)。 文件不必存在,但是文件夹路径必须存在。 如果确实存在相应的文件,则SQL Server遵循一组简单的规则:

  • If the ‘To database’ (from the General page) matches the restore database backup (i.e. restoring to matching databases), the respective files will be overwritten as part of the restore.

    如果“到数据库”(来自“常规”页面)与还原数据库备份匹配(即还原到匹配的数据库),则相应文件将作为还原的一部分被覆盖。
  • If the ‘To database’ does not match the restore database backup (i.e. restoring to a different database), the ‘Overwrite the existing database’ will need to be checked for the restore process to complete. Use this function with caution as you can potentially restore database backup information on top of data files from a completely different database.

    如果“到数据库”与还原数据库备份不匹配(即还原到其他数据库),则需要检查“覆盖现有数据库”以完成还原过程。 请谨慎使用此功能,因为您可能会从完全不同的数据库中恢复数据文件之上的数据库备份信息。

Generally, you can tell the databases differ based on the ‘Original File Name’ which is the internal name SQL Server uses to reference the respective files.

通常,您可以根据“原始文件名”告诉数据库不同,“原始文件名”是SQL Server用来引用各个文件的内部名称。

使用SQL Server Management Studio还原SQL数据库备份

Once your restore options are set, click Ok.

设置还原选项后,单击“确定”。

使用SQL Server Management Studio还原SQL数据库备份

结论 (Conclusion)

SQL Server Management Studio makes the restore process simple and is ideal if you seldom perform database restores. This process works in every version of SQL Server from Express to Enterprise. If you are using the Express version, you can download SQL Server Management Studio Express to get access to this interface.

SQL Server Management Studio使还原过程变得简单,如果您很少执行数据库还原,则是理想的选择。 此过程适用于从Express到Enterprise的每个版本SQL Server。 如果使用的是Express版本,则可以下载SQL Server Management Studio Express来访问此界面。

链接 (Links)

Download SQL Server Management Studio Express from Microsoft

从Microsoft下载SQL Server Management Studio Express

翻译自: https://www.howtogeek.com/50354/restoring-a-sql-database-backup-using-sql-server-management-studio/