在不還原資料的情況下復原資料庫 (Transact-SQL)Recover a Database Without Restoring Data (Transact-SQL)

適用於: 是SQL Server 否Azure SQL Database 否Azure SQL 資料倉儲 否平行處理資料倉儲 APPLIES TO: yesSQL Server noAzure SQL Database noAzure SQL Data Warehouse 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 RECOVERYRESTORE 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 RECOVERYRESTORE 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)