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.
migrated from stackoverflow.com Feb 24 '12 at 19:42
|
If you are using SQLCMD, you can use
|
|||
|
|
|
I agree, a T-SQL preprocessor is badly needed. I developed my own one in C#, which took me like an hour. Besides control over order of execution of SQL scripts, it also allows me to have macros that look like scalar UDFs and are convenient to use, but perform as fast as inline UDFs. |
|||
|
|
Along with the SQLCMD mode in Management Studio, you can also use a batch file to use as a master file to arrange and call all your sql files by using the SQLCMD utility. The SQLCMD mode is a simulation of the utility usage inside the Management Studio, so there's not big difference between the modes. Except that sometime I prefer to run batches (no more opening of M Studio...loading correct db...etc). I prefer to configure everything in the batch, including output files. |
|||
|
|
|
In the sense of the ancient C preprocessors definitely no
If you have a set of files with given absolute paths, which you want to include in a unconditional order, you can use the command line tool sqlcmd or use SSMS in sqlcmdmode as mentioned by @mfredrickson and @Marian. But if you want relative paths or conditional includes you need to use some wrapper calling sqlcmd (or one of its deprecated predecessors isql or osql). Currently at my job in this situation, I'm reviewing and extending old vbs and hta code. I'm not completely happy, but it is a pragmatic decision. It is working and the end user is at home with the hta GUI and no additional software installation is required. For a fresh design I would start thinking about using WPF and PowerShell to wrap calls of sqlcmd, but with our current customers I can't presume the presence of PowerShell V2. In even former times we wrote simple cmd batches for this purpose, ome of them still in use. I guess there are current tools, especially those targeting Workflows, which might be suitable here. I'm not familiar with those. |
|||
|
|
|
I like bernd_k's answer. Depending on how you named your scripts, like including a number, SQL Server PowerShell (SQLPS) could be used if you were running SQL Server 2008 or higher. Then even if you were using SQL 2005 you could utilize PowerShell and the SMO for 2005. Side note: I believe SQLCMD will eventually be put on the depreciated list and is being replaced with SQLPS, PowerShell. There are a few other options as well.
|
|||
|
|
