HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

The SQL BACKUP DATABASE Statement

The BACKUP DATABASE statement is used in SQL Server to create a full back up of an existing SQL database.

Syntax

 BACKUP DATABASE databasename
TO DISK = 'filepath';

The SQL BACKUP WITH DIFFERENTIAL Statement


A differential back up only backs up the parts of the database that have changed since the last full database backup.

Example

 BACKUP DATABASE databasename
TO DISK = 'filepath'
WITH DIFFERENTIAL;
You can click on above box to edit the code and run again.

BACKUP DATABASE Example


The following SQL statement creates a full back up of the existing database newDB" to the D disk:

Example

 BACKUP DATABASE newDB
TO DISK = 'D:\backups\newDB.bak';
You can click on above box to edit the code and run again.
Tip: Always back up the database to a different drive than the actual database . Then, if you get a disk crash, you will not lose your backup file along with the database.

BACKUP WITH DIFFERENTIAL Example


The following SQL statement creates a differential back up of the database "newDB":

Example

 BACKUP DATABASE newDB
TO DISK = 'D:\backups\newDB.bak'
WITH DIFFERENTIAL;
You can click on above box to edit the code and run again.

Tip: A differential back up reduces the back up time (since only the changes are backed up).