"collapse all' or "toggle outline" in SQL Server Management Studio 2008

60,970

Solution 1

It appears this feature does not exist. It has been recommended to Microsoft. I suggest voting it up; http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=368542

As a work-around, I'm using Notepad++ to edit locally. Its region identification isn't as good, but it's better than nothing.

Solution 2

This isn't a shortcut key, but there is a menu option in the Query Editor to do this.

Open your query and then go to Edit > Outlining > Toggle All Outlining.

This will toggle (i.e. expand/collapse) all nodes in the query.

Solution 3

A workaround is to use BEGIN and END.

BEGIN -- comment on/explain the region/outlined section

/*

TSQL goes here

*/

END

You will then be able to collapse the BEGIN.

Solution 4

In ssms 2017 -> There is an option in Tools > Options {see image}

The below illustrates @Triynko update to @Shawns answer

enter image description here

Solution 5

There is a free 3rd party add-in for SSMS called, SSMS Tools Pack. It provides several useful features, which includes collapsable regions and debug sections. By default, the regions are collapsed when you first open a .sql script.

http://www.ssmstoolspack.com/Features?f=9

For example:

--#region You can place comments here which are visible when the region is collapsed.

if object_id('MyTable') is null
begin
   create table MyTable 
   (
   constraint [pk_mytable] primary key clustered ( mytable_id ),
   mytable_id int not null  
   );
end;

--#endregion
Share:
60,970
Vincent
Author by

Vincent

Over 20 years of experience designing & building enterprise applications.

Updated on July 15, 2020

Comments

  • Vincent
    Vincent almost 4 years

    A new feature in SQL Server Management Studio 2008 is 'outlining' (the ability to collapse regions). It is awesome. However, by default all regions are expanded. I can't seem to find a way to 'collapse all' (also called 'toggle outline' in Visual Studio). Is anyone aware of a way to do this? I've been tasked with reviewing a 3,000 line stored procedure, and collapsing regions one-by-one is cumbersome.