How to recover a database backup to an existing database that is already in use _mssql

Source: Internet
Author: User
Tags mssql
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 = ten,--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 to 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.