Udostępnij za pośrednictwem


Recover a Database Without Restoring Data (Transact-SQL)

Usually, all of the data in a SQL 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.

The RESTORE syntax for a recovery-only database restore is as follows:

RESTORE DATABASE database_name WITH RECOVERY

[!UWAGA]

The FROM = <backup_device> clause is not used for recovery-only restores because no backup is necessary.

Example

The following example recovers the AdventureWorks2012 sample database in a restore operation without restoring data.

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

[Top]

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. For information about the phases of restore, see Restore and Recovery Overview (SQL Server).

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

The following example illustrates a recovery-only file restore of the files in a secondary filegroup, SalesGroup2, in the Sales database. 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;

[Top]

Examples of Completing a Piecemeal Restore Scenario with a Recovery-Only Restore

Simple recovery model

Full recovery model

Zobacz także

Odwołanie

RESTORE (Transact-SQL)

Koncepcje

Online Restore (SQL Server)

Piecemeal Restores (SQL Server)

File Restores (Simple Recovery Model)

File Restores (Full Recovery Model)