Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 restore db to specific directory

Author  Topic 

sirwan
Starting Member

4 Posts

Posted - 2013-05-04 : 19:02:01
Hi all
How can i restore a data base to a specific directory like d:\db_name.mdf .
And i need to do this by code
?????

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2013-05-06 : 11:53:53
Use the WITH MOVE clause in your restore statement.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2013-05-07 : 01:47:57
use the RESTORE FILELISTONLY FROM DISK = 'H:\test1.bak' to identify the files currently in the backup file
Then construct a sql statement using something like:
RESTORE DATABASE Test
FROM DISK = 'F:\mybackup.bak'
WITH MOVE 'TestData' TO 'D:\test.MDF',
MOVE 'TestLog' TO 'E:\test.LDF'



Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

sirwan
Starting Member

4 Posts

Posted - 2013-05-15 : 12:24:48
it work's Thank's :)
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2013-05-16 : 01:43:22
your welcome

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
   

- Advertisement -