How To Backup SQL Server Database With Examples

SQL Database: Definition

A database in Sql Server is a storage location where we can store our data. The SQL database uses tables to store our information in a normalizes way. So that, We can easily Select, Update and Delete the business data.

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

Syntax:

 SQL> BACKUP DATABASE databasename
      TO DISK = 'filepath'; 

Example 1:

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

The above SQL statement creates a full back up of an existing database "demoDB" to the E disk:


SQL BACKUP WITH DIFFERENTIAL Statement

The below SQL statement creates a differential back up of the database "demoDB"

Syntax:

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


Example 2:

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

The above SQL statement creates a full back up of an existing database "demoDB" to the E disk differentially:


Level SQL Server backup

This command uses the "WITH FILE" option to specify a file backup.

You need to specify the logical filename within the database which can be obtained by using the command sp_helpdb 'databaseName', specifying the name of your database.

Example:

BACKUP DATABASE demoDB FILE = 'demoDB' 
TO DISK = 'C:\demoDB_demoDB.FIL'
GO