Batch execute SQL files in a directory

Having to excecute hundreds of .sql files in an environment without port 1433 open led me to this nugget of a Usenet post: How to execute multi-file.

Here is the gist of it, the command line for executing all those .sql files with osql:

FOR %i IN (*.sql) DO OSQL -n -U sa -P sapassword -d databasename -i %i

I am sure I could have merged them all into one file or made some sort of batch vbs, but this did the trick nicely.

Posted on:

Comments are closed.