DOS – Batch Join SQL Files

We have all of our SQL script in source control.   Whenever I update the database I have to go through each file and run it individually.  I wanted a way to be able to run all SQL scripts.  So, I crated a DOS batch that would join all the files in a directory and add "GO" and CRLF between each script.
 
FOR %%A IN (*.SQL) DO (
 TYPE %%A >> AllSql.txt
 echo. >> AllSql.txt
 echo   GO >> AllSql.txt
 echo. >> AllSql.txt
 echo –%%A >> AllSql.txt
)
 
I was using Copy but I was getting NULLs in my resulting script, very strang.  I change the Copy to TYPE and everything seemed to work correctly
Also, echo. does CRLF
 
Resource
How to insert a carriage return with batch
 
How to write a DOS batch file to loop through files
 
 
 

Leave a Reply

Your email address will not be published. Required fields are marked *