Restore a differential database backup (SQL Server)

Applies to: yesSQL Server (all supported versions)

This topic describes how to restore a differential database backup in SQL Server by using SQL Server Direction Studio or Transact-SQL.

In This Topic

  • Before you begin:

    Limitations and Restrictions

    Prerequisites

    Security

  • To restore a differential database backup, using:

    SQL Server Management Studio

    Transact-SQL

  • Related Tasks

Before You Begin

Limitations and Restrictions

  • RESTORE is not allowed in an explicit or implicit transaction.

  • Backups that are created by more contempo version of SQL Server cannot be restored in earlier versions of SQL Server.

  • In SQL Server, yous tin restore a user database from a database backup that was created by using SQL Server 2005 (9.x) or a later version.

Prerequisites

  • Under the full or bulk-logged recovery model, before you can restore a database, you must back up the active transaction log (known equally the tail of the log). For more information, meet Back Upwards a Transaction Log (SQL Server).

Security

Permissions

If the database being restored does not exist, the user must have CREATE DATABASE permissions to be able to execute RESTORE. If the database exists, RESTORE permissions default to members of the sysadmin and dbcreator stock-still server roles and the owner (dbo) of the database (for the FROM DATABASE_SNAPSHOT option, the database always exists).

RESTORE permissions are given to roles in which membership data is always readily available to the server. Because fixed database role membership tin can be checked but when the database is accessible and undamaged, which is non always the case when RESTORE is executed, members of the db_owner stock-still database role practise not take RESTORE permissions.

Using SQL Server Management Studio

To restore a differential database backup

  1. Subsequently you lot connect to the appropriate instance of the Microsoft SQL Server Database Engine, in Object Explorer, click the server name to expand the server tree.

  2. Expand Databases. Depending on the database, either select a user database or expand System Databases, and then select a organization database.

  3. Correct-click the database, signal to Tasks, signal to Restore, and and then click Database.

  4. On the General page, utilise the Source section to specify the source and location of the backup sets to restore. Select i of the following options:

    • Database

      Select the database to restore from the drop-downwardly list. The list contains only databases that have been backed upwardly according to the msdb fill-in history.

    Annotation

    If the backup is taken from a different server, the destination server volition not have the backup history information for the specified database. In this example, select Device to manually specify the file or device to restore.

    • Device

      Click the scan (...) push to open the Select backup devices dialog box. In the Fill-in media type box, select one of the listed device types. To select i or more devices for the Backup media box, click Add together.

      Afterwards you add together the devices you lot desire to the Backup media list box, click OK to return to the General folio.

      In the Source: Device: Database list box, select the name of the database which should be restored.

      Note This list is simply available when Device is selected. Only databases that have backups on the selected device will be bachelor.

  5. In the Destination section, the Database box is automatically populated with the proper noun of the database to be restored. To alter the name of the database, enter the new name in the Database box.

  6. In the Backup sets to restore filigree, select the backups through the differential fill-in that you wish to restore.

    For data well-nigh the columns in the Backup sets to restore grid, run across Restore Database (General Page).

  7. On the Options page, in the Restore options panel, you can select any of the following options, if appropriate for your state of affairs:

    • Overwrite the existing database (WITH REPLACE)

    • Preserve the replication settings (WITH KEEP_REPLICATION)

    • Prompt before restoring each backup

    • Restrict admission to the restored database (WITH RESTRICTED_USER)

    For more data well-nigh these options, come across Restore Database (Options Folio).

  8. Select an selection for the Recovery land box. This box determines the state of the database afterwards the restore operation.

    • RESTORE WITH RECOVERY is the default behavior which leaves the database set up for use past rolling dorsum the uncommitted transactions. Additional transaction logs cannot be restored. Select this option if you are restoring all of the necessary backups at present.

    • RESTORE WITH NORECOVERY which leaves the database not-operational, and does non roll back the uncommitted transactions. Additional transaction logs can be restored. The database cannot be used until it is recovered.

    • RESTORE WITH STANDBY which leaves the database in read-only mode. It undoes uncommitted transactions, but saves the disengage actions in a standby file so that recovery furnishings tin can exist reverted.

    For descriptions of the options, see Restore Database (Options Page).

  9. Restore operations will neglect if there are active connections to the database. Cheque the Close existing connections pick to ensure that all agile connections between Management Studio and the database are closed.

  10. Select Prompt earlier restoring each backup if you wish to be prompted between each restore operation. This is not normally necessary unless the database is big and you wish to monitor the status of the restore performance.

  11. Optionally, utilize the Files page to restore the database to a new location. For aid with moving a database, encounter Restore a Database to a New Location (SQL Server).

  12. Click OK.

Using Transact-SQL

To restore a differential database backup

  1. Execute the RESTORE DATABASE statement, specifying the NORECOVERY clause, to restore the full database backup that comes before the differential database backup. For more information, see How to: Restore a Full Backup.

  2. Execute the RESTORE DATABASE statement to restore the differential database backup, specifying:

    • The name of the database to which the differential database backup is applied.

    • The backup device where the differential database backup is restored from.

    • The NORECOVERY clause if you have transaction log backups to apply afterwards the differential database backup is restored. Otherwise, specify the RECOVERY clause.

  3. With the total or bulk-logged recovery model, restoring a differential database backup restores the database to the point at which the differential database backup was completed. To recover to the point of failure, you lot must apply all transaction log backups created afterwards the last differential database backup was created. For more than data, see Apply Transaction Log Backups (SQL Server).

Examples (Transact-SQL)

A. Restoring a differential database backup

This example restores a database and differential database backup of the MyAdvWorks database.

              -- Assume the database is lost, and restore full database,    -- specifying the original full database backup and NORECOVERY,    -- which allows subsequent restore operations to proceed.   RESTORE DATABASE MyAdvWorks      FROM MyAdvWorks_1      WITH NORECOVERY;   Get   -- Now restore the differential database backup, the 2nd backup on    -- the MyAdvWorks_1 backup device.   RESTORE DATABASE MyAdvWorks      FROM MyAdvWorks_1      WITH FILE = 2,      RECOVERY;   Become                          

B. Restoring a database, differential database, and transaction log backup

This case restores a database, differential database, and transaction log backup of the MyAdvWorks database.

              -- Assume the database is lost at this point. Now restore the full    -- database. Specify the original total database fill-in and NORECOVERY.   -- NORECOVERY allows subsequent restore operations to proceed.   RESTORE DATABASE MyAdvWorks      FROM MyAdvWorks_1      WITH NORECOVERY;   GO   -- Now restore the differential database fill-in, the second backup on    -- the MyAdvWorks_1 fill-in device.   RESTORE DATABASE MyAdvWorks      FROM MyAdvWorks_1      WITH FILE = 2,      NORECOVERY;   Get   -- Now restore each transaction log backup created after   -- the differential database backup.   RESTORE LOG MyAdvWorks      FROM MyAdvWorks_log1      WITH NORECOVERY;   GO   RESTORE LOG MyAdvWorks      FROM MyAdvWorks_log2      WITH RECOVERY;   Get                          
  • Create a Differential Database Backup (SQL Server)

  • Restore a Transaction Log Backup (SQL Server)

See Likewise

Differential Backups (SQL Server)
RESTORE (Transact-SQL)