How to Backup and Restore a SQL Server Database? Step-By-Step Tutorial

Read time 7 minutes

Summary: Do you know how to backup and restore SQL database? It’s an easy task that anyone can complete with the SQL Server Management Studio or T-SQL queries. Follow the blog for a step-by-step guide to safely backup & restore database in SQL Server.

SQL Server Database contains data that is of critical importance for every other organization. Organizations are highly protective towards their data. Considering the importance of the SQL database, it is recommended to take regular SQL Server backups. These backups are crucial to restore SQL database without losing any data. Database backups help to prepare for worst-case scenarios and high-risk data loss situations.

In this article, we will guide you on “how to backup SQL Server database?” using different methods. To protect your SQL data, we will learn how to take full SQL database backup along with SQL differential backup. Additionally, we will also see how to restore SQL Server database from backup.

Why Backup SQL Server Database?

To understand the importance of creating backups, go through the points given below:

How to Backup Database in SQL Server?

You can backup SQL Server using SQL Server Management Studio, T-SQL queries, or with PowerShell.

Method 1: Backup SQL Server Database with Transact SQL

Follow the steps given below to create backup database with T-SQL:

Step 1: Open SQL Server Management Studio (SSMS) and click on New Query button.

Step 2: Run the following T-SQL command

USE TechForums19;

GO

BACKUP DATABASE TechForums19
TO DISK = ‘Z:\SQLServerBackups\TechForums19.Bak’
WITH FORMAT,
MEDIANAME = ‘Z_SQLServerBackups’,
NAME = ‘Full Backup of TechForums19’,

GO

Note: Above, TechForums19, is the database selected for backup, change it with the one you want to back up.

To create a differential backup, use the following command:

USE TechForums19;

GO

BACKUP DATABASE TechForums19
TO DISK = ‘Z:\SQLServerBackups\TechForums19.Bak’
WITH DIFFERENTIAL,
NAME = ‘Full Backup of TechForums19’,

Method 2: Backup SQL Server Database Using PowerShell

To create the SQL Server database backup using PowerShell, we’ll use the Backup-SqlDatabase cmdlet.

Step 1: Open Windows PowerShell as Administrator.

Step 2: Execute the below PowerShell command to create the full SQL Server Database backup:

Backup-SqlDatabase -ServerInstance Computer/Instance –Database TechForums19 –BackupAction Database

In the above command replace the following:

Method 3. Backup Using SSMS

SSMS can easily backup & restore database. The tool provides a graphical approach to backup entire database objects. This method is best for users looking for a non-technical method to backup SQL tables. Backup data with the following steps:

Step 1: Open the SSMS tool and connect to the database.

Step 2: Expand the Database option.

Step 3: Select and right-click the database you want to backup.

Step 4: Go to Tasks and click on Back Up.

Step 5: Select the Backup type as Full and click OK.

For SQL Server differential database backup, select the Backup type as Differential.

How to Restore SQL Server Database from a Backup?

To restore the data from a SQL database backup file you can use the SSMS tool or the T-SQL commands. However, before you begin with SQL Server restore from backup, do consider the backup file SQL version.

Method 1. Restore SQL Database Using T-SQL Queries

Use the steps given below to restore your database

Step 1: Open SSMS tool and click on New Query.

Step 2: Run the following SQL statements.

RESTORE DATABASE TechForums19
FROM DISK = ‘Z:\SQLServerBackups\TechForums19.Bak’

Use the same command as above to restore SQL server differential backup.

Method 2: Restore SQL with SSMS

You can restore the database without running any query with the following steps:

Step 1: Run SQL Server Management Studio.

Step 2: Right-click Databases and select Restore.

Step 3: Select the database you want to backup and click OK.

You can follow the steps to restore a differential SQL backup with SSMS. When you select the database, the SSMS tool will automatically list all the available backups (Full + Differential).

How to Restore SQL Server from a Corrupt Backup File?

The methods above will help you create full SQL Server database backups and differential backups. File backups are there to help you get out of database corruption situations but what to do when even the backup files turn corrupt or get damaged. In that case, you must use a SQL Backup Recovery tool.

Kernel SQL Backup Recovery is a professional tool used by many database administrators to repair corrupt SQL database file. The tool can restore SQL database from backup with complete data objects. Users can restore complete or selective data from the backup file. The best part about the tool is that you can directly move data from .bak file to live SQL Server database.

Conclusion

Creating file backups is not only a good practice but also insurance which saves time and money. And Kernel for SQL Database Recovery is there to fix the issues, when the database files turn corrupt, and you wonder how to repair corrupt SQL database. It is a one-stop-shop for SQL repair & recovery. Alternately, you can restore SQL database files even from damaged SQL backup files using Kernel SQL Backup Recovery tool.

Q. How to backup and restore SQL database?

Ans. You can do SQL Server backup and restore with the Microsoft’s SQL Server Management Studio application. Additionally, you can utilize Transact SQL queries or the Windows PowerShell to backup & restore SQL database.

Q. Can I restore SQL Server 2016 from a SQL Server 2019 BAK file?

Ans. No, you cannot. A SQL Server 2019 backup file can only restore SQL Server 2019 version. The SQL backup files are not forward or backward compatible. Therefore, always check the SQL version before you begin a SQL database restoration.

Q. What is differential database backup?

Ans. When you take a differential database backup, you only backup the changes made to the database since the last Full backup. It does not take a complete backup of your database. Only the new data added in database will be backed up with the differential backup.