Code Collapse and Expand Feature in SQL Server Management Studio 2008

Code Collapse and Expand Feature in SQL Server Management Studio 2008

  • Comments 16

In SQL Server Management Studio 2008, whenever you have a "block" of code (BEGIN....END, etc) SSMS will put a little plus-sign in the margin and allow you to "collapse" that block of code so you only see the BEGIN, not stuff underneath. If you're working with a really large set of code, that's helpful.

But I got an e-mail from a friend that said her SSMS didn't do that. I was kind of surprised, since I never had to do anything to make it work. We did a little digging, and come to find out it is in fact an option. Of course, we couldn't make it easy to find :) so I thought I would let you know where that option is in case you want to turn it off or back on (default, by the way, is on):


From the menu bar open Tools | Options

Open Text Editor | Transact-SQL | Intellisense (Yes, Intellisense. I have no idea why it is there. Just open it)

Then click the checkbox next to "Outline Statements" (No, I also have no idea why it is called that. I guess "Code Collapse" was too easy and wouldn't give me any material for a blog post)

Close everything out and re-open. Ta-da! By the way, this option is documented in Books Online, but not like this. Just thought you should know.

Leave a Comment
  • Please add 6 and 6 and type the answer here:
  • Post
  • There's an adding for 2005 that adds collapse:

    Nifty toolpack it is.

  • Nice feature... I use it all the time!  I think they called it outlining because Visual Studio also uses that terminology already for the same feature.

  • Nice...

    thx for the information..

    but in my SSMS..

    this feature only work at all comments, so i can use this to collapse n expand my own script (begin end, long select code etc...)

    can u give any tips so i can use this feature for my script??

  • Please vote up for the bug "Plus (+) and minus (-) sign on left of editor which is used to Collapse/Expand Code Blocks disappears when SQLCMD Mode is enabled in SQL Server Management Studio"

  • I have SSMS 2008 R2

    DB Server is SQL Server 2008.

    I have "Outline Statements" checked.

    but I do not have this feature.

  • It would be nice to be able to collapse / expand these code blocks via keyboard shortcuts... Visual Studio does it, I believe is Ctrl-M-M, Ctrl-M-L and Ctrl-M-O.

  • was it taken out in r2?

    it seems to show outlines when i open my sql fileon SQL 2008 server's query window but doesnt on my R2 machine's window

  • Can't tell you how many times I've gone to select a line or lines of code and accidentally collapsed a bunch. Not a huge deal but I'm so glad to have an out!  THANK YOU!

  • Thank you for the tip (on how to turn this *off*)!

    Coming from the SQL200 world, I'm not quite ready for this feature yet...

  • thanks for the note. My outline had disappeared but I think it went away b/c of the maximum script size block :)

  • So I can't disable Intellisense and have the Code Collapse and Expand Feature in the same time. Thank you Microsoft !!

  • In SQL Studio 2012, when I hover over a "minus" outline indicator, there is faint shading over the t-sql showing what will be collapsed. This shading does not have enough contrast to my liking. I found Tools > Options > Environment > Fonts and Colors > Show settings for: Text Editor > Display items: Outlining...(2 items). But these do not change the shading over the t-sql. I also tried searching MS Connect for 'intellisense outline statements' but had no success.

    Does anyone know how to change this shading?


  • So...


    I've so far only found keystroke shortcuts to do this, which only work on a number pad, which is not typically available on a laptop.

    Any help is appreciated!

  • Thank you - most annoying thing ever.

  • Well, that explains why it stopped working. I turned intelligence off so that it wouldn't interfere with my Red Gate tools.

    Thanks for helping. :D


Page 1 of 2 (16 items) 12