I come across the need occasionally to deploy a set of sql files that are all checked into source control in different files with a file hierarchy like this:
- Database Name
- Type of object (proc, table, view, etc)
- Name of object
When I go to deploy the scripts I need to manually combine all the SQL files into one to move to production, qa or test for deployment. After getting annoyed at lots of copy and paste I finally discovered an easy powershell script to combine all the files into one.
Steve points out at the end that if the file does not end with “GO” then combining multiple things, like stored procedures, together might result in unexpected behavior. I’ve done something similar to Steve’s script, except as you stream the content, append a newline, “GO,” and another newline.