问题
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.
回答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.
回答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.
回答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.
回答4:
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
回答5:
In ssms 2017 -> There is an option in Tools > Options {see image}
The below illustrates @Triynko update to @Shawns answer
回答6:
If you open a .sql script in Visual Studio then you can collapse the code in there.
回答7:
This feature was implemented in SQL Server Management Studio 2012 and is available for editions beyond also using CTRL + M etc - https://msdn.microsoft.com/en-us/library/ms174205(v=sql.110).aspx
回答8:
Ctrl+M,Ctrl+A is the default in SSMS 17.X.
You can change this by going to Tools > Options > Environment > Keyboard, then click on command Edit.CollapseAllOutlining and Assign your new shortcut keys.
回答9:
In my condition it was "Maximun Script Size" default is 1MB, mine was above 1Mb changed it to 5MB it works
Path is
Tools >> Options >> Text Editor >> TransactSQL >> Intellisense >> Maximum Script Size
来源:https://stackoverflow.com/questions/1850389/collapse-all-or-toggle-outline-in-sql-server-management-studio-2008