Database basics-data backup and recovery

How to backup the database

Backup database (system storage process)

Syntax format:

execute sp_addumpdevice [设备类型],[逻辑名],[物理名]

Description:

Statement Description
Equipment type Indicate the media type, which can be a diskhard disk type or a tapetape type
Logical name The logical name of the database backup
Physical name The path where the backup file is saved. Note: The backup file cannot be saved directly in the root directory of the disk

Delete backup device (system storage process)

When the created backup device is no longer needed, you can use the system storage process to sp_dropdevicedelete it. E.g:

execute sp_dropdevice [逻辑名],delete

Back up the database through T-SQL statements

[备份:备份数据库]
backup database [被备份的数据库名] to disk='备份文件路径';
-- 注意:被备份的数据库必须要存在,否则就会报错
[离线:离线数据库]
alter database [被恢复的数据库名] set offline with rollback immediate
[恢复:恢复数据库]
restore database [被恢复的数据库名] from disk='备份文件路径'
[在线:将数据库置于在线状态]
alter database [被恢复的数据库名] set online with rollback immediate

Guess you like

Origin blog.csdn.net/qq_42418169/article/details/106212549