Create a batch file to run the sql statements

Murth

Create a batch file to run the sql statements

by Murth » Thu, 27 Oct 2011 01:59:08

Hi

I have written stored procedures to create a database with db name as input parameter

I need to create a batch file to run the stored procedure with input value given in the command prompt along with the batch file will be my dbname, which will be used by the stored procedure to create the databse.

and also few sql statements to insert data into those tables after creating



Plz could any one help me out to create code to create a batch file

thanks in advance




Joe Web

Create a batch file to run the sql statements

by Joe Web » Sat, 29 Oct 2011 03:00:09

Check out OSQL. It's a command line tool that allows you to login to and execute sql statements against a SQL Server database. It's part of the SQL Server client components.

I don't have a system in front of me at the moment so you'll need to check the parameters here, but it should be something like:

OSQL -S servername -E -i inputfile.sql

Again double check the parameters since I'm doing this from memory. Open a command prompt and type
OSQL /

HTH...

Joe


Michael Hote

Create a batch file to run the sql statements

by Michael Hote » Mon, 31 Oct 2011 04:01:10

And if this is a SQL Server 2005 instance, you would use SQLCMD instead of OSQL.