SQL Server Docs

Restore Operations

The RESTORE statement restores a backup of a database or transaction log to a database. It can be used to recover a database to a specific point in time, to restore files, or to recover database states after a failure.

Key Concepts

RESTORE DATABASE [DatabaseName]
FROM DISK = N'path\to\backupfile.bak'
WITH [options];

Common options include RECOVERY, NORECOVERY, STANDBY, and REPLACE.

Examples

Full Database Restore

RESTORE DATABASE AdventureWorks2019
FROM DISK = N'C:\Backups\AdventureWorks2019_Full.bak'
WITH RECOVERY, 
     REPLACE;

Point-in-Time Restore

RESTORE DATABASE AdventureWorks2019
FROM DISK = N'C:\Backups\AdventureWorks2019_Full.bak' WITH NORECOVERY;

RESTORE LOG AdventureWorks2019
FROM DISK = N'C:\Backups\AdventureWorks2019_Log1.trn' WITH NORECOVERY;

RESTORE LOG AdventureWorks2019
FROM DISK = N'C:\Backups\AdventureWorks2019_Log2.trn' 
WITH STOPAT = '2024-03-15T14:30:00', RECOVERY;

Restore Options

Option Description
RECOVERY Brings the database online after restore.
NORECOVERY Leaves the database non-operational for additional restores.
STANDBY Leaves the database read-only and allows log shipping.
REPLACE Overwrites an existing database without checking for compatibility.
MOVE Specifies new file locations for data and log files.