SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Run SQL/T-SQL scripts on folder

By Daniel Marques,

A bat script to run all the sql/t-sql scripts in a specific folder.


- Using SQLCMD for running the scripts.

- Logging the results of your sql to a file per script.

- Input for scripts and log folders.

- Beginning and end times for each script.

- Check if the folders exist

- Total running duration of each script saved in the logs.


- Create a empty .bat or .cmd and copy and paste the code in it.

- Change your machine and instance name(for clusters) for single instance you just need your machine name.

- Put your credentials(if needed)

- Run the script, you will be prompt with the scripts and logs paths(can be the same).

- Just wait...the bat will do the rest :)

There are other scripts out there that can do this, this just one more, simple and working.

Use and abuse.

Daniel Marques

Total article views: 1014 | Views in the last 30 days: 17
Related Articles

Script to create datestamp folder causing issue

Script to create datestamp folder causing issue


Using Script Task to check if Folder Exists

Using Script Task to check if Folder Exists


MSDB sub-folder via script or MSI

How do I Create an MSDB folder via script or MSI?


Checking OS folder permissions

Checking OS folder permissions


Query to Delete all Folders, Sub-Folders and Files located in a Path

A script to help you cleanup Files/Folders & Sub-folders.