备份
BACKUP DATABASE [SnPrintZC] TO DISK = N'F:\sqlbackup\sp2' WITH NOFORMAT, NOINIT, NAME = N'备份说明', SKIP, NOREWIND, NOUNLOAD, STATS = 10
SnPrintZC 数据库名 disk 备份路径绝对值
恢复
RESTORE DATABASE [SnPrintZC] FROM DISK = N'F:\sqlbackup\sp2' WITH FILE = 1, NOUNLOAD, STATS = 5
脱机
ALTER DATABASE [SnPrintZC] SET OFFLINE WITH ROLLBACK IMMEDIATE;
状态
select name,state_desc from sys.databases
查看进程
EXEC sp_who2
杀死
KILL 1
恢复的时候,先做脱机处理
1 先看数据库是否还有人用 EXEC sp_who2
2 如果有人用 杀死进程 KILL 1 (1 为 EXEC sp_who2中返回的结果中使用数据库的pid)
3 执行脱机 ALTER DATABASE [SnPrintZC] SET OFFLINE WITH ROLLBACK IMMEDIATE;
4 查看数据库是否脱机 select name,state_desc from sys.databases
5 执行恢复命令 RESTORE DATABASE [SnPrintZC] FROM DISK = N'F:\sqlbackup\sp2' WITH FILE = 1, NOUNLOAD, STATS = 5