Connecting Tech Pros Worldwide Forums | Help | Site Map

How to restore a database through command prompt

Newbie
 
Join Date: Oct 2008
Posts: 2
#1: Oct 29 '08
Hi,

I have a MS SQL database backup file kept at location "c:\backup_20Aug08.bak". I want to restore the database through command prompt. I am going to create batch file out of these dos commands. So that the restore process will be automated. I am using SQL express edition. Can anybody help me to guide on this?

Thanks in advance,
Rohan.

ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Oct 31 '08

re: How to restore a database through command prompt


Am not sure if that would be possible, I mean if DOS batch file alone.

You could use OSQL to connect to SQL server and RESTORE from your backup. Setup a schedule on your OS to run this in specific time or frequency.

Or you can do it the other way, create a stored proc that will restore these backup and schedule it as daily running job. You can also set notification emails for success or failed restore.

Happy Coding!

-- CK
Reply