Consolidated SQL Script file from multiple files

by sanjay 15. October 2012 10:00

23 Feb 2013

As a developer you will need to supply scripts that upgrade the application database from time to time. You can either bundle all your scripts in one folder , zip them and send to your client and ask them to run by date modified or any other order. But it would be obviously much easier for them to be able to run one individual consolidated script.

This can be done as follows

 

for %%I in (*.sql) do type "%%I" >> consolidated.sql 

 

One problem you might face is that you might need a new line to be enter after every file.

for this create a loop and put these in a batch file (.bat)

for %%I in (*.sql) do

(

    type "%%I" >> consolidated.sql

    echo. >> consolidate.sql

)

 

finally you shall put additional "GO" in the end of every file

for %%I in (*.sql) do

(

    type "%%I" >> consolidated.sql

    echo. >> consolidated.sql

    echo. GO >> consolidate.sql

)

 

Please drop a comment if you have improvements.

 

 

Tags: ,

SQL

Comments (3) -

Admin
Admin United Kingdom
2/22/2013 7:19:48 PM #

Test comment

Reply

tech111
tech111 Australia
2/23/2013 7:37:55 AM #

you can do this with .net app too.. but i guess this way is faster

Reply

pyrmont
pyrmont Australia
2/25/2013 2:05:58 AM #

LOL someone did have this .NET app at my workplace.

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading