SQL BACKUP DATABASE Keyword
The BACKUP DATABASE
command is used in SQL Server to create a full backup or a differential backup of an existing SQL database. Backups help protect data from loss due to corruption, accidental deletion, or hardware failure.
In professional environments, it’s best practice to back up to a different disk from where the database is stored.
SQL BACKUP DATABASE Syntax (SQL Server only)
Full Backup:
BACKUP DATABASE database_name
TO DISK = 'file_path.bak';
Differential Backup:
BACKUP DATABASE database_name
TO DISK = 'file_path.bak'
WITH DIFFERENTIAL;
SQL BACKUP DATABASE Example (SQL Server only)
This statement creates a full backup of the testDB
database and saves it to the D drive:
BACKUP DATABASE testDB
TO DISK = 'D:\backups\testDB.bak';
This statement creates a differential backup of the same database:
BACKUP DATABASE testDB
TO DISK = 'D:\backups\testDB.bak'
WITH DIFFERENTIAL;
Note: These commands will not work in our playground because TechKubo uses SQLite, and SQLite does not support the
BACKUP DATABASE
SQL statement. In SQLite, database backup is handled outside SQL using external tools or commands.