For some years now, SQL Server Management Studio (SSMS) has had the ability to use code outlining, the same way that other Visual Studio applications can.
This can be very useful when you are trying to navigate around a large script file.
The simplest usage is to collapse or expand a region of code. Note that in the following script, code regions have been automatically added by SSMS:
This allows us to click on the outline handles, and collapse the code:
Note that when the region of code is collapsed, the name of the region is shown as the first line of the code within the region, truncated.
If you hover over the ellipsis (the dot dot dot) at the beginning of the code region, you'll be shown what's contained within the region:
Now, what's missing?
I'd love to be able to just drag regions around.
I'd also love to be able to name the regions better. It's not too bad if the regions are procedures or functions but for other chunks of code, there's really no good option. Note that if I add a comment immediately above the code, it's not part of the same region. It might be better if it was like that, or if a specific comment could be treated as a region heading:
In the Edit menu, the Outlining submenu doesn't show anything else useful at this point, apart from bulk operations:
"I'd also love to be able to name the regions better. It's not too bad if the regions are procedures or functions but for other chunks of code, there's really no good option."
Have you tried using a block, BEGIN and END, to demarcate regions. You could even add a comment above the block to give it a title. I use this on a daily basis to tame unwieldy stored procs, etc., at a company that relies heavily upon them.
Good article, mate. Thanks.
Sounds like a good option Todd, as long as the code regions can align with where that would work.
Never thought of using BEGIN+END to demarcate wherever you wish—thanks!
You are most welcome
Another possible option I saw somewhere is something like this…
BEGIN — Insert dummy person
END — Insert dummy person
When collapsed, all you see is
BEGIN — Insert dummy person…
Yes, perfect thanks Zach