Thursday, 26 September 2013

Running all scripts in a directory against a particular database


At some point, you may have the need to rapidly apply a bunch of scripts on a particular database.  Rather than manually opening each in Management Studio and executing them, you can use sqlcmd to run all scripts in a particular directory, in alphabetical order.  Should save you some time:

for %f in (“c:\path\to\dir\*.sql”) do sqlcmd -S [SERVER_NAME] -d [DATABASE_NAME] -i “%f” -b


No comments: