RESTORE

RESTORE is a Transact-SQL statement in SQL Server used to retrieve or recover data from a backup. It performs operations such as restoring data, transaction logs, and files groups from a backup, replacing existing databases, or creating a new database. It is an essential command for disaster recovery scenarios.

Example

RESTORE DATABASE TestDB
FROM DISK = 'C:\BackupFolder\TestDB.bak'
WITH RECOVERY

Output

5 percent processed.
10 percent processed.
...
100 percent processed.
Database 'TestDB' restored successfully.

Explanation

The given code is used to restore a SQL Server database named ‘TestDB’ from a backup file located at ‘C:\BackupFolder\TestDB.bak’. The ‘WITH RECOVERY’ option brings the database online immediately after the restore operation is finished. The output indicates the process of restoration in percentages and confirms successful restoration upon completion.

Example

RUN {
SET UNTIL SCN 1000;
RESTORE DATABASE;
RECOVER DATABASE;
}

Output

executing command: SET until clause
...
executing command: RESTORE
...
executing command: RECOVER
...

Explanation

The above example script runs restore and recovery on a database up to System Change Number (SCN) 1000. If you know the SCN, you can use it to recover the database to a specific point in time.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.