Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi.. i would like to restore a database backup file in a different name using sql query. plz help me out..

with thnks & rgrds
ageesh..
Posted

1 solution

First run a query to find the logical name of the datafiles

Restore filelistonly from disk = 'd:\backup\Data.bak'

Where "d:\backup\Data.bak" should be your backupo name

Which should show the Logical filenames in the backup set.

Now

Restore database Newdatabase from disk = 'd:\backup\Data.bak'
with move 'LogicalnameforMDF' to 'd:\SQLData\NewDatabase.MDF',
move 'LogicalnameforLDF' to 'd:\SQLData\NewDatabase_Log.lDF', stats

Where
1. "d:\backup\Data.bak" is your Backup name
2. "LogicalnameforMDF" is the Logicalname as shown in the previous query for the MDF File
3. "d:\SQLData\NewDatabase.MDF" physical filename on the disk(where the data to be restored)
4. "LogicalnameforLDF" is the Logicalname as shown in the previous query for the LDF File (Log)
5. "d:\SQLData\NewDatabase_Log.lDF" is the physical File name of the Log
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900