How to include an sql file within another sql file in MS SQL?
Use sqlcmd utility.
Extract you might find interesting:
-i input_file[,input_file2...]
Identifies the file that contains a batch of SQL statements or stored procedures. Multiple files may be specified that will be read and processed in order. Do not use any spaces between file names. sqlcmd will first check to see whether all the specified files exist. If one or more files do not exist, sqlcmd will exit.
Example:
sqlcmd -dDataBaseName -E -Stcp:ServerName\instancename -imaster.sql
Master.Sql:
:r file1.sql
:r file2.sql
Use the Business Intelligence Development Studio that comes with SQL Server to do this. Create a new SSIS Package. Inside this package create several Execute SQL Tasks
in the Control Flow for each file you have and set SQLSourceType
to FileConnection
and choose your file.