Bill Greer
Bill Greer

Reputation: 3156

How to restore a SQL Server backup to another database?

I want to restore a database to 12/29/2016. I want to restore to another name so I do not lose the state of the original database. The name of my database is APDatabase.

How do I modify the SQL below to restore to a database called TempAPDatabase? I also want to be careful not to lose any of the backup information which is stored on the disk as 87A991B1-9305-45C1-A461-9B1A3174A707.

USE [master]

BACKUP LOG [APDatabase] 
TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MYSQLSERVER\MSSQL\Backup\APDatabase_LogBackup_2017-03-13_10-52-54.bak' 
WITH NOFORMAT, NOINIT,  
     NAME = N'APDatabase_LogBackup_2017-03-13_10-52-54', 
     NOSKIP, NOREWIND, NOUNLOAD,  NORECOVERY, STATS = 5

RESTORE DATABASE [APDatabase] 
FROM DISK = N'{87A991B1-9305-45C1-A461-9B1A3174A707}10' 
WITH FILE = 1, NORECOVERY, NOUNLOAD, STATS = 5

RESTORE LOG [APDatabase] 
FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MYSQLSERVER\MSSQL\Backup\APDatabase_LogBackup_2017-03-10_06-47-10.bak' 
WITH FILE = 1, NOUNLOAD, STATS = 5, STOPAT = N'2016-12-29T00:00:00'
GO

Upvotes: 0

Views: 1304

Answers (1)

Wes H
Wes H

Reputation: 4439

Assuming the rest of your command is correct, you just need to state the new name as the database you're restoring.

RESTORE DATABASE [TempAPDatabase] 
FROM DISK = N'{87A991B1-9305-45C1-A461-9B1A3174A707}10' 
WITH FILE = 1, NORECOVERY, NOUNLOAD, STATS = 5

RESTORE LOG [TempAPDatabase] 
FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MYSQLSERVER\MSSQL\Backup\APDatabase_LogBackup_2017-03-10_06-47-10.bak' 
WITH FILE = 1, NOUNLOAD, STATS = 5, STOPAT = N'2016-12-29T00:00:00'
GO

Upvotes: 1

Related Questions