Quickstart: Backup and restore a SQL Server database with SSMS
Applies to: SQL Server
In this quickstart, you create a new database, take a full backup of it, and then restore it.
For a more detailed how-to, see Create a full database backup and Restore a database backup using SSMS.
Prerequisites
To complete this quickstart, you need:
Create a test database
Launch SQL Server Management Studio (SSMS) and connect to your SQL Server instance.
Open a New Query window.
Create your test database using the following Transact-SQL (T-SQL) code.
USE [master]; GO CREATE DATABASE [SQLTestDB]; GO USE [SQLTestDB]; GO CREATE TABLE SQLTest ( ID INT NOT NULL PRIMARY KEY, c1 VARCHAR(100) NOT NULL, dt1 DATETIME NOT NULL DEFAULT GETDATE() ); GO USE [SQLTestDB]; GO INSERT INTO SQLTest (ID, c1) VALUES (1, 'test1'); INSERT INTO SQLTest (ID, c1) VALUES (2, 'test2'); INSERT INTO SQLTest (ID, c1) VALUES (3, 'test3'); INSERT INTO SQLTest (ID, c1) VALUES (4, 'test4'); INSERT INTO SQLTest (ID, c1) VALUES (5, 'test5'); GO SELECT * FROM SQLTest; GO
Refresh the Databases node in Object Explorer to see your new database.
Take a backup
To take a backup of your database, follow these steps, using SQL Server Management Studio or Transact-SQL:
- Launch SQL Server Management Studio (SSMS) and connect to your SQL Server instance.
- Expand the Databases node in Object Explorer.
- Right-click the database, hover over Tasks, and select Back up....
- Under Destination, confirm that the path for your backup is correct. If you need to change the path, select Remove to remove the existing path, and then Add to type in a new path. You can use the ellipses to navigate to a specific file.
- Select OK to take a backup of your database.
To read more about the different backup options, see BACKUP.
Restore a backup
To restore your database, follow these steps:
Launch SQL Server Management Studio (SSMS) and connect to your SQL Server instance.
Right-click the Databases node in Object Explorer and select Restore Database....
Select Device:, and then select the ellipses (...) to locate your backup file.
Select Add and navigate to where your
.bak
file is located. Select the.bak
file and then select OK.Select OK to close the Select backup devices dialog box.
Select OK to restore the backup of your database.
Clean up resources
Run the following Transact-SQL command to remove the database you created, along with its backup history in the msdb
database:
EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'SQLTestDB'
GO
USE [master];
GO
DROP DATABASE [SQLTestDB];
GO
Related content
- Restore SQL Server databases on Azure VMs
- Quickstart: Restore a database to Azure SQL Managed Instance with SSMS
- Restore a database from a backup in Azure SQL Database
- Back Up and Restore of SQL Server Databases
- SQL Server backup to URL for Microsoft Azure Blob Storage
- Create a Full Database Backup
- Restore a Database Backup Using SSMS