Hướng dẫn backup database sql server 2014

     

In this quickstart, you"ll create a new database, take a full backup of it, and then restore it.

Bạn đang xem: Hướng dẫn backup database sql server 2014

For a more detailed how-to, see Create a full database backup & Restore a backup using SSMS.

Prerequisites

To complete this quickstart, you"ll need:

Create a chạy thử database

Open a New Query window.

Run the following Transact-SQL (T-SQL) code to lớn create your chạy thử database.

USE ;GOCREATE DATABASE ;GOUSE ;GOCREATE TABLE SQLTest (ID INT NOT NULL PRIMARY KEY,c1 VARCHAR(100) NOT NULL,dt1 DATETIME NOT NULL mặc định GETDATE());GOUSE GOINSERT 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");GOSELECT * FROM SQLTest;GORefresh the Databases node in Object Explorer to lớn see your new database.

Take a backup

To take a backup of your database, follow these steps:

Expand the Databases node in Object Explorer.Right-click the database, hover over Tasks, và select Back up....Under Destination, confirm that the path for your backup is correct. If you need to change the path, select Remove to lớn remove the existing path, và then Add lớn type in a new path. You can use the ellipses khổng lồ navigate to a specific file.Select OK lớn take a backup of your database.

Xem thêm: Các Phần Mềm Test Phần Cứng Máy Tính Không Cần Cài Đặt, Phần Mềm Test Máy Tính Toàn Diện

*

Alternatively, you can run the following Transact-SQL command to back up your database. The path may be different on your computer:

USE ;GOBACKUP DATABASE TO DISK = N"C:Program Filesjdomain.vn SQL ServerMSSQL14.MSSQLSERVERMSSQLBackupSQLTestDB.bak" WITH NOFORMAT, NOINIT,NAME = N"SQLTestDB-Full Database Backup", SKIP, NOREWIND, NOUNLOAD, STATS = 10;GOTo read more about the different backup options, see BACKUP (Transact-SQL).

Restore a backup

To restore your database, follow these steps:

Right-click the Databases node in Object Explorer và select Restore Database....

*

Select Device:, and then select the ellipses (...) lớn locate your backup file.

Select Add and navigate khổng lồ where your .bak tệp tin is located. Select the .bak file & then select OK.

Select OK lớn close the Select backup devices dialog box.

Select OK lớn restore the backup of your database.

*

Alternatively, you can run the following Transact-SQL script to restore your database. The path may be different on your computer:

USE ;GORESTORE DATABASE FROM DISK = N"C:Program Filesjdomain.vn SQL ServerMSSQL14.MSSQLSERVERMSSQLBackupSQLTestDB.bak" WITH file = 1, NOUNLOAD, STATS = 5;GO

Clean up resources

Run the following Transact-SQL command to remove the database you created, along with its backup history in the msdb database:


Chuyên mục: Domain Hosting