SQL SERVER – Combined Multiple .SQL files into One Single File

Here is an interesting problem which I enjoyed solving yesterday.

There were multiple SQL Files in my one folder. When I had to send it to my friend I had to collect all the files into a folder and zip it to send it via email. My friend who was using mobile device told me that it is difficult to see the content of the file on a mobile device so it would be nice if I can just send all the SQL files combined in one single file and send it to him.

I loved the idea, but the challenge was that there are over 100s of the files were there and combining them into a single file would be a manual task for hours. I did not like the solution and I went online to find some cool solution. After a while I found a solution that I can use wiht command prompt to combine multiple files into a single file and it is easy to do so.

Here is an example. Let us create three SQL Files.

SQL SERVER - Combined Multiple .SQL files into One Single File combinesql1

SQL SERVER - Combined Multiple .SQL files into One Single File combinesql2

Now we will execute the following command in command prompt which will combine all the three files into a single file.

The command is

type *.sql > OneFile.sql

SQL SERVER - Combined Multiple .SQL files into One Single File combinesql3

Above command will combine all the three files into a single called OneFile.sql.

Following image displays the content of the OneFile.sql which is the concatenation of all the sql files in the folder.

SQL SERVER - Combined Multiple .SQL files into One Single File combinesql4

I enjoyed solving this little problem.

Reference: Pinal Dave (https://darkslategrey-bat-805937.hostingersite.com)

Batch
Previous Post
EXCEL / SQL SERVER – Extract the Domain from an Email Address
Next Post
SQL SERVER – Search Records with Single Quotes

Related Posts

Leave a Reply