SQL Server Database Restoration Using SQL Script and SSMS

 

Introduction:

Data restoration is essential in database administration for protecting sensitive information, responding to unforeseen circumstances, and migrating databases from one machine to another. There are several ways to restore databases. Using Microsoft SQL Server, which includes utilizing SQL scripts and SQL Server Management Studio (SSMS). We will go through both procedures for recovering/ or restoring the database.

Part 1: Using the script, restore the SQL Server database.

Step 1)Create a backup of the source database as the first step. Make sure you have a current backup of the source database before beginning the restoration procedure. Use the script below to make a complete database backup:

Go to  SqlEditor to execute the following command. 

The above path is the default path used by SSMS however we can save the backup file at another location according to our choice as below.


Step 2) Examine the Target SQL Server Instance's Backup Sets/ Check the availability of the Backup file. Establish a connection to the SQL Server instance you wish to use to restore the database. By executing the command below, you may confirm the backup sets that are accessible for restoration Sometimes Backup folders doest have access rights make sure you have full rights on the Backup folder.

RESTORE FILELISTONLY

FROM DISK = 'C:\Databackup\DemoDB.bak'




Step 3) Restoring the database is step three.

Execute the following script with the necessary changes to restore the database.


As an example:




After the Execution of the above query database will be restored with the data from the Backup file.


Part 2: Restoring of SQL Server Database with SSMS User Interface tool

Launch SQL Server Management Studio (SSMS) in step one.

To restore the database,  connect to the target SQL Server instance.

Access the Restore Database Wizard in step two.

Right-click "Databases" in the Object Explorer and then choose "Restore Database."

Choosing the Source and Destination in Step 3

Chose the three dots on the right side and select the path of the Backup file





Select "Device" as the source in the Restore Database wizard and use the "..." button to travel to the location of your backup file. Make that the target database name is entered correctly.

Step 4: Pick backup options and sets.

Pick the backup collections you want to restore. Additionally, you may choose settings like overwriting existing databases, moving files, and recovery mode.

Step 5: Examine and Carry Out

After reading the restoration operation overview, click "OK" to begin the restoration procedure.

Conclusion:

To protect data integrity and recover from possible calamities, database managers must regularly restore SQL Server databases. In this post, we looked at using SQL scripts and SQL Server Management Studio (SSMS) as two methods for recovering SQL Server databases. Understanding the database restoration process is crucial for guaranteeing data dependability and business continuity, regardless of whether you like the scripts' adaptability or SSMS's user-friendly interface. In order to be well-prepared for any unforeseen scenarios, keep in mind to periodically generate backups, adhere to recommended practices, and test the restoration procedure.

In certain cases, the backup you intend to restore is faulty, or the database it restores has missing data. This could occur as a result of SQL database corruption on the server you choose to restore the database to. To check for corruption in the database, use the following DBCC CHECKDB command:

The database is damaged if the command produces consistency errors (DBCC CHECKDB ('Test') with NO)INFOMSGS, ALL_ERRORMSGS). Run the 'REPAIR_ALLOW_DATA_LOSS' minimum suggested repair option to resolve the corruption problem.

Caution! Data loss may occur if the 'REPAIR_ALLOW_DATA_LOSS' option is used.












Post a Comment

1 Comments

  1. Please share how to create script for restore and back in sql

    ReplyDelete