The BACKUP DATABASE keyword in SQL is used to create a backup of a database in SQL Server. It allows you to create a copy of the entire database or a specific portion of it for safety, recovery, or archival purposes. This is essential for ensuring data integrity and for recovering data in case of failure or corruption.
Here is the basic syntax for backing up a database:
BACKUP DATABASE database_name
TO DISK = 'file_path\backup_file.bak';
Parameters:
database_name: The name of the database you want to back up.TO DISK: Specifies that the backup is to be saved as a file on disk.'file_path\backup_file.bak': The path and name of the backup file where the database will be stored.
Example:
BACKUP DATABASE MyDatabase
TO DISK = 'C:\backups\MyDatabase_backup.bak';
Additional Options:
WITH COMPRESSION: Compresses the backup to reduce the size.WITH FORMAT: Overwrites any existing backup at the target location.WITH NORECOVERY: Specifies that the backup is part of a backup chain, and the database will be in a restoring state after the backup.WITH INIT: Replaces any existing backup at the target location.
Example with additional options:
BACKUP DATABASE MyDatabase
TO DISK = 'C:\backups\MyDatabase_backup.bak'
WITH FORMAT, COMPRESSION;
This command creates a full backup of the MyDatabase database and stores it at the specified path.
No comments:
Post a Comment