Avatar of cheryl9063
cheryl9063
Flag for United States of America asked on

sql restore from 2 .bak files

What is the correct syntax. I need to restore one database called hat but I have 2 .bak files that need to be restored for 1 database. See my code below.. What is the correct way to write this?

RESTORE FILELISTONLY FROM disk = N'E:\Backups\hat0.bak'

RESTORE FILELISTONLY FROM disk = N'E:\Backups\hat1.bak'
 
-- Perform the restore of the database from the backup file.  
-- Replace 'move' names (MDFLogicalName, LDFLogicalName) with those found in  
-- the previous filelistonly command

restore database hat
from disk = N'E:\Backups\hat0.bak'  and N'E:\Backups\hat1.bak'  
with move 'hat_Data' to 'J:\MDFs\hat.mdf',
     move 'hat_Log' to 'I:\Data\hat.ldf',
replace, stats=10;
Microsoft SQL Server 2008Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Ephraim Wangoya

8/22/2022 - Mon
sameer_goyal

3 steps to restore from each backup

Step 1 - Retrieve Logical File Name

RESTORE FILELISTONLY
FROM DISK = N'E:\Backups\hat0.bak'
GO


Step 2 - Change to Single user Mode

ALTER DATABASE Hat
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE

Step 3 - Restore Database

RESTORE DATABASE Hat
FROM DISK = N'E:\Backups\hat0.bak'
WITH MOVE 'Hat_Data' TO 'J:\MDFs\hat.mdf',
MOVE 'Hat_log' TO  'I:\Data\hat.ldf'

ALTER DATABASE Hat SET MULTI_USER


Repeat Step 1 thru 3 for second back up file
ASKER CERTIFIED SOLUTION
Ephraim Wangoya

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61