数据库操作

 -- 建测试数据库
create database ilovemk8

-- 添加数据文件
alter database [ilovemk8] 
add file
(name='ilovemk8_test_2',filename='E:\SQLDATA\ilovemk8_test_2.ndf') to filegroup [PRIMARY]

-- 备份数据库文件
BACKUP DATABASE [ilovemk8] FILE = N'ilovemk8_test_2' 
to DISK = N'D:\ilovemk8_file_02.bak' WITH FORMAT,init

-- 备份日志
BACKUP LOG ilovemk8 TO DISK = N'D:\ilovemk8_log_03.bak' with format,init;

-- 设数据库offline
alter database ilovemk8 set offline

-- 删除数据文件
-- delete file : E:\SQLDATA\ilovemk8_test_2.ndf

-- 设数据库online
ALTER DATABASE ilovemk8 SET ONLINE

-- 备份尾部日志
BACKUP LOG ilovemk8 TO DISK =N'D:\ilovemk8_log_04.bak' WITH CONTINUE_AFTER_ERROR,init

-- 还原数据文件备份
RESTORE DATABASE ilovemk8 FILE ='ilovemk8_test_2' 
FROM DISK =N'D:\ilovemk8_file_02.bak' WITH norecovery

-- 还原日志备份
RESTORE LOG ilovemk8 FROM DISK =N'D:\ilovemk8_log_03.bak' WITH norecovery

-- 还原尾部日志,还原完成.
RESTORE LOG ilovemk8 FROM DISK =N'D:\ilovemk8_log_04.bak'

-- 测试打开数据库,正常.
use ilovemk8



 

你可能感兴趣的:(数据库操作)