patternsqlMajor
Is there a concept of an "include file" in SQL Server?
Viewed 0 times
filesqlincludeconceptserverthere
Problem
I have a set of scripts that need to be run in a certain order. I would like to create a "master file" that lists all of the other files and their correct order. Basically like an include file from C++ or ASP/VBScript.
Solution
If you are using SQLCMD, you can use
:r FileName
Parses additional T-SQL statements and SQLCMD commands from the file
specified by FileName into the statement cache. FileName is read
relative to the startup directory for Visual Studio. The file is read
and executed after a batch terminator is encountered. You can issue
multiple :r commands. The file can include any SQLCMD command,
including the batch terminator that is defined in Tools, Options. You
can use :r in a pre-deployment or post-deployment script to include
other scripts.
:r FileName to include a separate .sql file.:r FileName
Parses additional T-SQL statements and SQLCMD commands from the file
specified by FileName into the statement cache. FileName is read
relative to the startup directory for Visual Studio. The file is read
and executed after a batch terminator is encountered. You can issue
multiple :r commands. The file can include any SQLCMD command,
including the batch terminator that is defined in Tools, Options. You
can use :r in a pre-deployment or post-deployment script to include
other scripts.
Context
StackExchange Database Administrators Q#13891, answer score: 23
Revisions (0)
No revisions yet.