SQL Keyword - BACKUP DATABASE

Backup Database

The Backup Database keyword is used to take or create a full backup of an existing SQL database.

A Database Backup is a copy of SQL Server data that can be used to restore and recover the data after a failure.

We can take multiple backup copies of one database at different times.

A backup file is stored with .bak extension.

Syntax

BACKUP DATABASE <BACKUP_NAME> TO DISK = <FILE_PATH_BACKUP_FILE_NAME>;

Example

BACKUP DATABASE MYDB TO DISK = 'E:\backups\mydbbackup.bak';

Differential Backup

A differential backup captures only the data that has changed since the last full backup.

After that, we worked on that database, so again we want to take a backup of the changes. There is no need to take a full backup; instead, use a differential backup.

So using differential backup only changes after a full backup has been taken. As a result, no additional space is required for backup, and backup time can be reduced. 

Syntax

BACKUP DATABASE <BACKUP_NAME> TO DISK = <FILE_PATH_BACKUP_FILE_NAME> WITH DIFFERENTIAL; 

Example

BACKUP DATABASE MYDB TO DISK = 'E:\backups\mydbbackup.bak' WITH DIFFERENTIAL;

Summary

The Backup Database keyword is used to take or create a full backup of an existing SQL database.