• No categories


I’m Attending


Execute all SQL Scripts in a Directory

Posted in: General by Steve on November 18, 2011

For my own sanity, I can never remember  this so I’m just posting it

Open CMD Prompt

CD to the directory where all the scripts are located

Use for Windows Authentication:

C:>for %f in (*.sql) do sqlcmd /S <servername> /d <dbname> /E /i "%f"

OR for Username/password:

C:>for %f in (*.sql) do sqlcmd /S <servername> /d <dbname> /U <username> /P <password> /i "%f"

And instead of outputting to the screen, i’ll usually redirect it out to a file so I can review all scripts later