| Author |
Topic |
|
ajcool123
Starting Member
8 Posts |
Posted - 2008-05-15 : 10:45:21
|
| Hi Guys,I am trying to figure out a way to restore a database programatically. Here is how I do it now. Right click on the database, select Restore. Browse out to my computer and find the .BAK file. Select the database and go into 'Restore Options' I have to physically change the .MDF and .LOG paths since I am getting this backup is not coming from my computer. I select 'Overwrite the existing database' then click restore. My problem is that I have to change the paths to the MDF and LOG files. How could I automate this? Thank you!! |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2008-05-15 : 10:48:28
|
you need to specify a default path in your program for the machine you're restoring into... standardization is the way to goor are you using ssms? if yes, then there is no way, because those textboxes get filled up automatically based on the backup informationquote: Originally posted by ajcool123 Hi Guys,I am trying to figure out a way to restore a database programatically. Here is how I do it now. Right click on the database, select Restore. Browse out to my computer and find the .BAK file. Select the database and go into 'Restore Options' I have to physically change the .MDF and .LOG paths since I am getting this backup is not coming from my computer. I select 'Overwrite the existing database' then click restore. My problem is that I have to change the paths to the MDF and LOG files. How could I automate this? Thank you!!
--------------------keeping it simple... |
 |
|
|
ajcool123
Starting Member
8 Posts |
Posted - 2008-05-15 : 11:15:39
|
| SSMS? I am using sql server management studio, yeah the boxes are being filled by the paths from the .bak of whoever backed up the initial database. There is NO way I can acomplish this with a script or even writing some code to do it? I would love to have a little prog that will all the input of .bak location, .mdf location, .log location, and give database name, and it will restore it.what does anyone think? |
 |
|
|
Van
Constraint Violating Yak Guru
462 Posts |
Posted - 2008-05-15 : 11:25:16
|
| What about the RESTORE DATABASE command. You can use the WITH MOVE option to move the files where you need them. It's well documented in BOL. |
 |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2008-05-15 : 11:27:57
|
see syntax at the end on this linkhttp://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1173442,00.html" SSMS? I am using sql server management studio," |
 |
|
|
ajcool123
Starting Member
8 Posts |
Posted - 2008-05-15 : 11:28:26
|
| okay cool how would something like that look? what would i be moving is my question, i just need to change the paths to the MDF and LOG file i would think right? i appreciate all the help. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-15 : 12:58:30
|
| Here is an example restore command using the MOVE option to move the files to a different path:RESTORE DATABASE dbNameFROM DISK = 'F:\Backup\dbName.bak'WITH REPLACE, MOVE 'dbName_Data' TO 'F:\Data\dbName.mdf', MOVE 'dbName_Log' TO F:\Log\dbName.ldf'You will need to determine the logical names of your database. You can do that with RESTORE FILELISTONLY.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
ajcool123
Starting Member
8 Posts |
Posted - 2008-05-15 : 13:41:16
|
| Thanks for all the help. I found a very easy way to do this. On the restore screen you can just click "Script" at the top and output the code to a script. This makes it so much easier to get a perfect script with all desired options. |
 |
|
|
|