恢复数据库但不还原数据 (Transact-SQL)Recover a Database Without Restoring Data (Transact-SQL)

适用对象:是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

通常,恢复数据库之前,将还原 SQL ServerSQL Server 数据库中的所有数据。Usually, all of the data in a SQL ServerSQL Server database is restored before the database is recovered. 但是,还原操作可以恢复数据库而不实际还原备份;例如,恢复那些与数据库一致的只读文件时。However, a restore operation can recover a database without actually restoring a backup; for example, when recovering a read-only file that is consistent with the database. 这称为仅恢复还原 。This is referred to as a recovery-only restore. 当脱机数据已与数据库一致且只需变为可用时,仅恢复还原操作将完成恢复数据库并使数据联机。When offline data is already consistent with the database and needs only to be made available, a recovery-only restore operation completes the recovery of the database and bring the data online.

仅恢复还原可以针对整个数据库或一个或多个文件或文件组进行。A recovery-only restore can occur for a whole database or for one or more a files or filegroups.

仅恢复数据库还原Recovery-Only Database Restore

在以下情况下仅恢复数据库还原十分有用:A recovery-only database restore can be useful in the following situations:

  • 您未在还原位于还原顺序中的最后备份时恢复数据库,现在希望恢复该数据库并使其联机。You did not recover the database when restoring the last backup in a restore sequence, and you now want to recover the database to bring it online.

  • 数据库处于备用模式,但您希望在不应用其他日志备份的情况下可以更新数据库。The database is in standby mode, and you want to make the database updatable without applying another log backup.

仅恢复数据库还原的 RESTORE 语法是:The RESTORE syntax for a recovery-only database restore is as follows:

RESTORE DATABASE *database_name* WITH RECOVERY

备注

FROM =<backup_device> 子句不用于仅恢复还原,因为不需要任何备份。The FROM = <backup_device> clause is not used for recovery-only restores because no backup is necessary.

示例Example

以下示例在还原操作中恢复 AdventureWorks2012AdventureWorks2012 示例数据库而不还原数据。The following example recovers the AdventureWorks2012AdventureWorks2012 sample database in a restore operation without restoring data.

-- Restore database using WITH RECOVERY.  
RESTORE DATABASE AdventureWorks2012  
   WITH RECOVERY  

仅恢复文件还原Recovery-Only File Restore

在以下情况下仅恢复文件还原十分有用:A recovery-only file restore can be useful in the following situation:

数据库按段落进行还原。A database is restored piecemeal. 完成主文件组的还原之后,一个或多个未还原的文件变为与新数据库的状态一致,这也许是因为这些文件最近始终是只读的。After restore of the primary filegroup is complete, one or more of the unrestored files are consistent with the new database state, perhaps because it has been read-only for some time. 只需恢复这些文件即可;无需复制数据。These files only have to be recovered; data copying is unnecessary.

仅恢复还原操作将脱机文件组中的数据变为联机状态;不会有数据复制、重做或撤消这些阶段。A recovery-only restore operation brings the data in the offline filegroup online; no data-copy, redo, or undo phase occurs. 有关还原阶段的信息,请参阅还原和恢复概述 (SQL Server) For information about the phases of restore, see Restore and Recovery Overview (SQL Server).

仅恢复文件还原的 RESTORE 语法是:The RESTORE syntax for a recovery-only file restore is:

RESTORE DATABASE *database_name* { FILE **=**_logical_file_name_ | FILEGROUP **=**_logical_filegroup_name_ }[ **,**...*n* ] WITH RECOVERY

示例Example

以下示例显示了 SalesGroup2数据库中辅助文件组 Sales 中文件的仅恢复文件还原。The following example illustrates a recovery-only file restore of the files in a secondary filegroup, SalesGroup2, in the Sales database. 已在段落还原的初始步骤中还原了主文件组,并且 SalesGroup2 与还原的主文件组一致。The primary filegroup has already been restored as the initial step of a piecemeal restore, and SalesGroup2 is consistent with the restored primary filegroup. 只需一条语句即可恢复此文件组并使其变为联机状态。Recovering this filegroup and bringing it online requires only a single statement.

RESTORE DATABASE Sales FILEGROUP=SalesGroup2 WITH RECOVERY;  

使用仅恢复还原完成段落还原方案的示例Examples of completing a piecemeal restore scenario with a recovery-only restore

简单恢复模式Simple recovery model

完整恢复模式Full recovery model

另请参阅See Also

联机还原 (SQL Server) Online Restore (SQL Server)
段落还原 (SQL Server) Piecemeal Restores (SQL Server)
文件还原(简单恢复模式) File Restores (Simple Recovery Model)
文件还原(完整恢复模式) File Restores (Full Recovery Model)
RESTORE (Transact-SQL)RESTORE (Transact-SQL)
还原和恢复概述 (SQL Server)Restore and Recovery Overview (SQL Server)