Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call SQL query from bat file on SQL server 2005

Status
Not open for further replies.

Steel811

Programmer
Jan 2, 2008
26
0
0
US
Hello all,

I am very new to SQL server 2005, and have been tasked with scripting out a database restore into SQL server 2005. I am using a batch file which is executed on the SQL Server 2005 machine to copy the database backup from the remote machine (SQL server 2000 standard) to the local machine, and then would like to run an SQL query from the local machine (c:\software\queries\db_restore.sql). Can this be done using OSQL? And if so, does anyone know what the syntax would be?

Here's what I think it might be:

osql -U webmaster -P password -i c:\software\queries\db_restore.sql"

Thanks in advance,
Sheel Shah
 
i use a simple script for dev work against sql 05 express. it would probally look something like:
Code:
sqlcmd -U [user id] -P [password] -S [server] -d [database] -i [full path to script] -o [full path to log file]
example
Code:
sqlcmd -U foo -P bar -S .\SqlExpress -d MyDB -i "c:\scripts\restore.sql" -o "c:\db logs\restore.log"
-o is good for logging errors and print statments. without it errors are not logged (i think.)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Jason,

Thank you very much for your assistance, this command worked perfectly!

Sheel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top