Home > SQL Queries, SQL Server, Tips & Tricks > Concatenate multiple .sql files into a single file.

Concatenate multiple .sql files into a single file.

Often we receive the scripts from our customers in multiple files. Sometimes as many as 70 to 80 files. Although I have an SSIS package to execute these .sql scripts, I sometimes use the DOS command to generate a single file by concatenating these set of files and execute it as a single file. Although this is not the best way to work. it is often very fast & easy .

The command used is “TYPE” .

Go to the appropriate folder ( where you have place all files) and execute the command from command prompt. A sample is as given below.

C:\Documents and Settings\joe>cd "C:\Allfiles\SqlFiles"
C:\Allfiles\SqlFiles> type *.sql > allinone.sql

The concatenated file can be executed, which is equivalent to executing other 70 files. Hope this post was of some help. :)

Advertisements
  1. yousufs
    February 11, 2010 at 11:51 am

    Thanks.it was helpful..

  2. July 30, 2012 at 6:54 pm

    the cmd copy command case fails while joining two sql scripts including special characters such as ♥ ☻☺. Any work around for this?

  3. April 9, 2014 at 8:52 am

    nice!!thank its work and resolve my problem!!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: