SQLCMD Batch File with script in batch file

dgold

SQLCMD Batch File with script in batch file

by dgold » Mon, 10 May 2010 05:24:05

I am using the following batch file to execute a script that creates a db and all its objects in the local sql express:

sqlcmd -S (local)\SQLExpress -i C:\CreateDB.sql

This works fine, but I'm wondering if there's an easy way to put the script in the batch file, so users don't have to worry about putting the script in the C drive. I tried getting rid of the i parameter and pasting the script from the sql file into the batch file, but it didn't work.

Thanks,

Dave



Xinwei Hong - MSF

SQLCMD Batch File with script in batch file

by Xinwei Hong - MSF » Wed, 12 May 2010 06:25:06

You can echo your script to a temp file in your batch file and then use the -i to run it.