I am filling in lots of predefined data into a table (in my post-deployment sql script) Is there way to create C# style regions so I can collapse chunks of inserts for readability and sanity?
Here's a short sample (#region is commented out):
MERGE INTO [MYTable] AS Target
USING (VALUES
--#region Measurement_Id = 1 'Flow' for all reasources
( 1, 1, 1, 45, NULL, NULL)
,( 2, 2, 1, 56, NULL, NULL)
,( 3, 3, 1, NULL, NULL, NULL)
,( 4, 4, 1, 67.5, 87, NULL)
,( 5, 5, 1, NULL, NULL, NULL)
,( 6, 6, 1, 54., NULL, 87)
,( 7, 7, 1, NULL, NULL, NULL)
--#endregion
--#region Measurement_Id = 2 'Disc' for all reasources
( 1, 1, 2, NULL, NULL, NULL)
,( 2, 2, 2, NULL, NULL, NULL)
,( 3, 3, 2, NULL, NULL, NULL)
,( 4, 4, 2, NULL, NULL, NULL)
,( 5, 5, 2, NULL, NULL, NULL)
--#region
...
) AS Source ([Measurement_Id],[Measurement_Nm],[Measurement_Cd],[Measurement_Desc],[IsActive_Ind])
ON (Target.[Measurement_Id] = Source.[Measurement_Id])
There is no native support, but it is possible to realize it using an add-in.
I develop SSMSBoost add-in (www.ssmsboost.com) for SSMS and have added
--#region [name]
--#endregion
syntax support in last version (2.12). There is also an option to auto-parse opened files, so that regions will be displayed immediately.
Database - how to create regions in TSQL (SQL Server 2008)
"Regions and Debug sections
Regions behave in the same way as in Visual Studio. You can collapse them and expand them. Debug sections are sections that get commented when you change your script to Release configuration. A debug section is also a collapsable region. If you deploy a script in debug mode with added debug sections it will fail when run from SSMS without SSMS Tools Pack installed. You can of course comment those sections yourself by simply searching for start and end text of the debug sections".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With