Skip to main content
CSharpUniversity ASP.NET and C# lessons

The search runs entirely in your browser over the published lesson list.

Backing up a database to a file

A backup turns a database into a file. That file can be moved to another machine, kept as a safety copy or used to seed a new environment.

The command

SQL
BACKUP DATABASE Shop
TO DISK = 'C:\backups\Shop.bak'
WITH INIT;

Good habits

  • Back up before any change you might want to undo.
  • Keep the backup somewhere other than the machine that holds the database.
  • Test a restore now and then, because a backup you cannot restore is not a backup.
Note the version. A backup can be restored on the same or a newer engine, not on an older one. If you plan to move it to another machine, check the version there first.

The reverse operation is restoring a database from a backup file.

New lessons by email

Leave your address and get a short note whenever a fresh lesson is published. No account needed and you can stop at any time.

Thank you. Your address has been noted in this browser session. Connect a mailing service to deliver the notes for real.