Search code examples
sql-servercommand-promptsql-scripts

Command prompt - throgh a lot of statements - running each one separately


I have a folder with 55 .sql files, SQL scripts.

Each file consists of 10000 insert statements. I'm using this command to run each file:

C:\sqlcmd -S . -d Minuf_Customers_July -i C:\ACL\MyScript3.sql

And I need to do it for MyScript1 , MyScript2.. to MyScript54.

Is there a way to loop through all the commands in the command prompt?

But it is important! that the each row will run separately because otherwise it will throw an "out of memory" error.


Solution

  • The DOS command for is your friend.

    for %f in (*.sql) do sqlcmd -S . -d Minuf_Customers_July -i %f
    

    The command help for gives details of various options.