bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/SQL/SQL Database
SQL•SQL Database

SQL BACKUP DATABASE Statement

The BACKUP DATABASE Statement

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

Syntax

BACKUP DATABASE
databasename
TO DISK = '
filepath
';

BACKUP DATABASE Example

The following SQL creates a full backup of the existing database "testDB" to the D drive:

Example

BACKUP DATABASE testDB
TO DISK = 'D:\backups\testDB.bak';

Tip

Always place the backup database in a different drive than the original database! If you get a disk crash, you will not lose your backup file along with the database.

The BACKUP WITH DIFFERENTIAL Statement

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

A differential backup requires at least one prior full backup!

Syntax

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

BACKUP WITH DIFFERENTIAL Example

The following SQL creates a differential backup of the database "testDB":

Example

BACKUP DATABASE testDB
TO DISK = 'D:\backups\testDB.bak'
WITH
 DIFFERENTIAL;

Tip

A differential backup reduces the backup time (since only the changes are backed up).

Previous

SQL DROP DATABASE Statement

Next

SQL CREATE TABLE Statement

This chapter

Overview
21

Lessons

50m

Read time

1. SQL CREATE DATABASE Statement2. SQL DROP DATABASE Statement3. SQL BACKUP DATABASE Statement4. SQL CREATE TABLE Statement5. SQL DROP TABLE Statement6. SQL ALTER TABLE Statement7. SQL Constraints8. SQL NOT NULL Constraint9. SQL UNIQUE Constraint10. SQL PRIMARY KEY Constraint11. SQL FOREIGN KEY Constraint12. SQL CHECK Constraint13. SQL DEFAULT Constraint14. SQL CREATE INDEX Statement15. SQL AUTO INCREMENT Field16. SQL Working With Dates17. SQL Views18. SQL Injection19. SQL Parameters20. SQL Prepared Statements21. SQL Hosting

On this page

The BACKUP DATABASE StatementBACKUP DATABASE ExampleThe BACKUP WITH DIFFERENTIAL StatementBACKUP WITH DIFFERENTIAL Example