如何恢复数据库备份到一个已存在的正在使用的数据库上
更新时间:2007年01月13日 00:00:00 作者:
USE master -- (Cant sit in the database whilst its being restored!)
GO
ALTER DATABASE MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
-- Restore Full Backup
RESTORE DATABASE MyDatabase
FROM DISK = x:\MSSQL\BACKUP\MyBackupFilename_Full.BAK
WITH
REPLACE,
NORECOVERY, -- Use if more T/Logs to recover
-- RECOVERY, -- Use if NO more T/Logs to recover
STATS = 10, -- Show progress (every 10%)
MOVE MyDatabase_Data TO x:\MSSQL\DATA\MyDatabase.mdf,
MOVE MyDatabase_Log TO x:\MSSQL\DATA\MyDatabase.ldf
GO
-- Optional restore Differential Backup
RESTORE DATABASE MyDatabase
FROM DISK = x:\MSSQL\BACKUP\MyDatabase_Diff.BAK
WITH
-- RECOVERY -- Use if NO more file to recover
NORECOVERY -- Use if there are T/Logs to recover
GO
-- Optional restore Transaction Log Backup
RESTORE DATABASE MyDatabase
FROM DISK = x:\MSSQL\BACKUP\MyDatabase_yyyymmdd_hhmm_Trans.BAK
WITH
-- RECOVERY -- Use if NO more T/Logs to recover
NORECOVERY -- Use if more T/Logs to recover
GO
-- Set the database ready for use (after all backups have been restored)
RESTORE DATABASE MyDatabase RECOVERY
GO
-- Rename logical names (only needed if restoring from a backup for a Different database):
ALTER DATABASE MyDatabase
MODIFY FILE (NAME = OrigDatabase_Data, NEWNAME = MyDatabase_data)
GO
ALTER DATABASE MyDatabase
MODIFY FILE (NAME = OrigDatabase_Log, NEWNAME = MyDatabase_log)
GO
GO
ALTER DATABASE MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
-- Restore Full Backup
RESTORE DATABASE MyDatabase
FROM DISK = x:\MSSQL\BACKUP\MyBackupFilename_Full.BAK
WITH
REPLACE,
NORECOVERY, -- Use if more T/Logs to recover
-- RECOVERY, -- Use if NO more T/Logs to recover
STATS = 10, -- Show progress (every 10%)
MOVE MyDatabase_Data TO x:\MSSQL\DATA\MyDatabase.mdf,
MOVE MyDatabase_Log TO x:\MSSQL\DATA\MyDatabase.ldf
GO
-- Optional restore Differential Backup
RESTORE DATABASE MyDatabase
FROM DISK = x:\MSSQL\BACKUP\MyDatabase_Diff.BAK
WITH
-- RECOVERY -- Use if NO more file to recover
NORECOVERY -- Use if there are T/Logs to recover
GO
-- Optional restore Transaction Log Backup
RESTORE DATABASE MyDatabase
FROM DISK = x:\MSSQL\BACKUP\MyDatabase_yyyymmdd_hhmm_Trans.BAK
WITH
-- RECOVERY -- Use if NO more T/Logs to recover
NORECOVERY -- Use if more T/Logs to recover
GO
-- Set the database ready for use (after all backups have been restored)
RESTORE DATABASE MyDatabase RECOVERY
GO
-- Rename logical names (only needed if restoring from a backup for a Different database):
ALTER DATABASE MyDatabase
MODIFY FILE (NAME = OrigDatabase_Data, NEWNAME = MyDatabase_data)
GO
ALTER DATABASE MyDatabase
MODIFY FILE (NAME = OrigDatabase_Log, NEWNAME = MyDatabase_log)
GO
相关文章
oracle忘记sys/system/scott用户密码的解决方法
一、忘记除SYS、SYSTEM用户之外的用户的登录密码。 二、忘记SYS用户,或者是SYSTEM用户的密码。 三、如果SYS,SYSTEM用户的密码都忘记或是丢失。 解决方法2013-03-03sql server启动不了, MSSQL 18052错误: 9003,严重度: 20,状态: 1 .
今天在配置服务器的时候,sqlserver发现无法运行了,到日志中看到 MSSQL 18052错误: 9003,严重度: 20,状态: 1 ,经过下面的方法解决了2015-01-01Sql学习第四天——SQL 关于with cube,with rollup和grouping解释及演示
CUBE 生成的结果集显示了所选列中值的所有组合的聚合。ROLLUP 生成的结果集显示了所选列中值的某一层次结构的聚合,接下再看看对grouping的解释,感兴趣的朋友可以参考下哈2013-03-03
最新评论