共用方式為


如何:還原差異資料庫備份 (Transact-SQL)

此主題說明如何還原差異資料庫備份。

若要還原差異資料庫備份

  1. 執行 RESTORE DATABASE 陳述式並指定 NORECOVERY 子句,以還原在差異資料庫備份之前的完整資料庫備份。如需詳細資訊,請參閱<如何:還原完整備份>。

  2. 執行 RESTORE DATABASE 陳述式以還原差異資料庫備份,請指定:

    • 將套用差異資料庫備份的資料庫名稱。

    • 將要還原差異資料庫備份的備份裝置。

    • 如果在還原差異資料庫備份之後,您有交易記錄備份可以套用,則指定 NORECOVERY 子句。否則,指定 RECOVERY 子句。

  3. 使用完整或大量記錄復原模式,還原差異資料庫備份可將資料庫還原到完成差異資料庫備份的時間點。若要復原到失敗點,您必須套用上次建立差異資料庫備份後所建立的所有交易記錄備份。如需詳細資訊,請參閱<如何:套用交易記錄備份 (Transact-SQL)>。

範例

A. 還原資料庫與差異資料庫備份

這個範例還原 MyAdvWorks 資料庫與差異資料庫備份。

-- 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
GO
-- Now restore the differential database backup, the second backup on 
-- the MyAdvWorks_1 backup device.
RESTORE DATABASE MyAdvWorks
   FROM MyAdvWorks_1
   WITH FILE = 2,
   RECOVERY
GO

B. 還原資料庫、差異式資料庫及交易記錄備份

這個範例還原 MyAdvWorks 資料庫、差異式資料庫及其交易記錄備份。

-- Assume the database is lost at this point. Now restore the full 
-- database. Specify the original full database backup and NORECOVERY.
-- NORECOVERY allows subsequent restore operations to proceed.
RESTORE DATABASE MyAdvWorks
   FROM MyAdvWorks_1
   WITH NORECOVERY
GO
-- Now restore the differential database backup, the second backup on 
-- the MyAdvWorks_1 backup device.
RESTORE DATABASE MyAdvWorks
   FROM MyAdvWorks_1
   WITH FILE = 2,
   NORECOVERY
GO
-- 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
GO