Skip to content

SQL BACKUP DATABASE for SQL Server

BACKUP DATABASE writes a copy of a whole database to a file, which can later be restored if the original is lost or damaged. It is a SQL Server statement; other databases back up with separate tools, listed at the end of this page.

A full backup copies the entire database:

BACKUP DATABASE ProductionAccounts
TO DISK = 'E:\Backups\ProductionAccounts.bak';

A differential backup copies only what has changed since the last full backup. It is smaller and quicker to make, so a common routine is a full backup each week and a differential each night:

BACKUP DATABASE ProductionAccounts
TO DISK = 'E:\Backups\ProductionAccounts-diff.bak'
WITH DIFFERENTIAL;

To restore, you need the last full backup and then the latest differential taken after it.

Database How it backs up
PostgreSQL the pg_dump tool, run from the command line
MySQL the mysqldump tool, run from the command line
SQLite the .backup command in the sqlite3 tool, or a copy of the database file while nothing is writing to it
Oracle the RMAN tool