DROP DATABASE database_name;
Use the RESTORE DATABASE command.
Full Database Restore Command:
RESTORE DATABASE database_name FROM backup_location TAKEN AT timestamp INTO target_database_name WITH REPLACE WITHOUT PROMPTING;
database_name
: Name of the database in the backup.backup_location
: Path to the directory where the backup file resides.timestamp
: Timestamp of the backup (visible in backup history or the filename).target_database_name
: (Optional) Name of the database you want to create or overwrite.WITH REPLACE
: Forces overwrite of an existing database.Suppose you have a backup of the database MYDB
in /backups
taken on 202412140735
. You can restore it as:
RESTORE DATABASE MYDB FROM '/backups' TAKEN AT 202412140735 INTO MYDB WITH REPLACE WITHOUT PROMPTING;
You need to restore the full backup first and then apply the incremental backups in sequence:
RESTORE DATABASE MYDB FROM '/backups' TAKEN AT 202412140735 WITHOUT PROMPTING; RESTORE DATABASE MYDB INCREMENTAL FROM '/backups' TAKEN AT 202412150800 WITHOUT PROMPTING;
After restoring, you may need to apply transaction logs if the database was enabled for archive logging. Use the ROLLFORWARD DATABASE command:
ROLLFORWARD DATABASE MYDB TO END OF LOGS AND COMPLETE;
After restoring, connect to the database to ensure it was restored successfully:
CONNECT TO MYDB;
LIST HISTORY BACKUP
command to get a list of backups:
LIST HISTORY BACKUP ALL FOR database_name;