How to View and Restore SQL Server Backup File
Introduction:
SQL Server provides the option to create and restore the database from backup whenever required. This will help users to prevent data loss in case of disaster. The SQL Server keeps the backup of its database in a separate backup file i.e .bak file. This backup file can be saved on a separate disk drive. The backup file cannot be viewed directly by opening it, you need to restore it to view its database.
SQL Server provides different options for creating and restoring a database from .bak file. There are two different ways that we can use to restore SQL .bak file.
Tip: If you want to recover corrupt .bak file of SQL Server then, you can utilize SQL Backup Recovery tool.
Methods to View SQL Server .bak File
In order to recover database from .bak file, the SQL Server provides two different ways to view and restore the backup file from a specific location.
-
- By using T-SQL
- By using SQL Server Management Studio
We can use above options to restore SQL Server .bak file. So, first of all, we will know how to restore SQL Server .bak file using the T-SQL script.
Restore SQL Backup File Using T-SQL :
To restore a .bak file in SQL Server, you need to first create a backup of your database and then you can restore it. If you have already created a full database backup then you can use below T-SQL script to restore the full database backup from a .bak file.
RESTORE DATABASE AdventureWorks FROM DISK = 'E:\AdventureWorks.BAK'
GO
the above T-SQL script will help you in restoring the database from the specified location and will create and restore the database if it does not already exist.
Restore SQL .bak File Using Management Studio:
To restore database using SQL Server management studio follow the below steps:
- Connect to SQL Server using Windows or mixed mode authentication.
- In object explorer, Select the Databases and Right click on it then click on Restore Database…
- Now, Specify the source and location of the backup sets by choosing either from the database or from the device.
- In ‘Specify backup’ window, Set the ‘Bakup media’ and click on Add to select the .bak file which is to be restored.
- Now, browse the backup file you want to restore and click on Ok then again click on Ok to complete the process.
- After performing the above steps a new window will appear by displaying the restoration process completed successfully.
The above procedure will help you in restoring the backup file using SQL Server management Studio.
Conclusion:
In this section, we learned, how to view and restore corrupted bak file in SQL Server database and how we can use T-SQL script and SQL Server Management Studio to restore a database using .bak file.
SQL Server uses different clauses to restore its database from a .bak file. In this section, we have restored a full backup, if someone trying to restore differential and transaction log backup, then do not forget to use With Norecovery clause in your statement.