CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Friday, May 01, 2009

Restore Sql database using sqlcmd and batch file

RESTORE DATABASE TESTDB FROM DISK = 'C:\TESTDB\TESTDB.BAK' WITH REPLACE

This command restores the database from the local drive to the sqlserver.

Put these lines in “RestoreDB.bat” file

@echo off
sqlcmd -E -S .\DA -i RestoreDB.sql -o RestoreDB.log
@echo off
pause

Place the following code in “RestoreDB.sql”

USE MASTER
RESTORE DATABASE TESTDB FROM DISK = 'C:\TESTDB\TESTDB.BAK' WITH REPLACE

Double click the RestoreDB.bat file to restores the dbs from local drive.

Post a Comment