How to Restore SQL Server Database From Backup?
A Database is defined as a structured form of data that is stored database a computer or data in an organized manner and can be accessed in various ways. It is also the collection of schemas, tables, queries, views, etc. Databases help us with easily storing, accessing, and manipulating data held on a computer. The Database Management System allows a user to interact with the database. In this article, we will see how can we restore SQL Server Database from Backup.
For the demonstration purpose, we will create one database named ‘geeks’.
Step 1: Create Database
Use the below SQL statement to create database called geeks;
CREATE DATABASE geeks;
you can see database with name ‘geeks’ is created.
Step 2: Use database
Step 3: Table definition
We have the following demo_table in the database.
CREATE TABLE demo_table (FIRSTNAME varchar(20), LASTNAME varchar(20), GENDER varchar(10), AGE int);
Step 4: Insert values
Following command is used to insert values into the table.
INSERT INTO demo_table VALUES ('ROMY','KUMARI','FEMALE', 22), ('PUSHKAR', 'JHA', 'MALE', 23), ('SOUMYA', 'SHRIYA', 'FEMALE', 22), ('NIKHIL', 'KALRA', 'MALE', 23), ('ROHIT', 'KUMAR', 'MALE', 23),
Step 5: View data of the table
SELECT * FROM demo_table;
Restoring of database can be done through Object explorer in SQL Server.
Steps to restore database:
- Select View from menu bar.
- Select Object explorer option. Object explorer will be appeared on left side of the screen.
- Right click on Database folder and select ‘Restore Database’ option.
- The dialog box will open, select device option and browse the backup media.
- After selecting the Backup media, click OK
- Database will be restored successfully.
Now, for demonstration of restoring the database. Delete the geeks database.
Step 6: Delete the Database
DROP DATABASE database_name;
We can not drop the database while in use.
DROP DATABASE geeks;
geeks database is deleted. You can not find geeks database in the object explorer.
Step 7: Restore database
- Right click on database and select ‘Restore database’ option
- Select ‘device’ option and add backup media
- Click Ok button
- Prompt will appear showing the message as “Database restored successfully”. Click OK.
- Check Object explorer.
‘geeks’ database is restored successfully.