In this article, we will learn how to get a full backup of the database using SQL query.

To create a full backup of an existing SQL database in SQL Server, the BACKUP DATABASE statement is used.

Syntax

BACKUP DATABASE DatabaseName
TO DISK = 'filepath';

Example

The subsequent statement would create a full backup of the existing database “TheCodeHubs”.

BACKUP DATABASE TheCodeHubs
TO DISK = 'D:\DBBackup\Backup_1.bak';

DIFFERENTIAL Statement

A DIFFERENTIAL statement is used to get back up of parts of the database, that have changed since the last full database backup.

A DIFFERENTIAL statement reduces the backup time because only the changes are backed up.

Syntax

BACKUP DATABASE DatabaseName
TO DISK = 'filepath'
WITH DIFFERENTIAL;

Example

The subsequent statement would create a differential back up of the database “TheCodeHubs”.

BACKUP DATABASE TheCodeHubs
TO DISK = 'D:\DBBackup\Backup_2.bak'
WITH DIFFERENTIAL;

 

Also, check How To Delete/Drop SQL DB Using Query