Run SQL/T-SQL scripts on folder

  • Comments posted to this topic are about the item Run SQL/T-SQL scripts on folder

  • What I've found to be very handy when writing batch files like this is to have an option to get a reminder of what the batch does, and what parameters are to be expected (if any) and to ensure that you've remembered to set the internal values before running.  In your case, as no parameters are expected, if passed a ?, it could give instructions.  It usually takes the form of something like this:

    (at the very beginning of the batch file)
    if "%1"=="?" then GOTO :Instructions

    (near the end of the file, as the last line of functioning code)

    ECHO BatchSQL (no parameters)
    ECHO pathScripts = %pathScripts%, pathlogs=%pathlogs%
    ECHO This batch will execute all .SQL scripts stored in %pathScripts% and output the results of the scripts in separate files within %pathlogs%.
    ECHO Note: If the pathScripts and pathlogs are incorrect above, they are set within the batch itself.

  • One of our systems has about 500 stored procedure scripts that need to be run on a release. To do this I concatenate all the scripts together in one file. At the DOS prompt you just need to type the following:
    COPY *.sql all.txt
    REN all.txt all.sql
    You then have a file (all.sql) containing all the scripts in one file. You have to make sure they are all saved with the same encoding (I use ASCI) and all the procedure scripts have a GO and new line at the end.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply