Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#region functionality in SSMS 2008

Using Sql Server 2008, is there any functionality similar to #region in Visual Studio?

I'm aware that nodes appear to allow collapsing of SQL segments, but as far as I know, this is based on the syntax of the SQL statement.

While that is close to what I'm after, I'm wondering if there is a way to define a section of code, regardless of syntax, similar to #region/#endregion.

Any thoughts?

like image 952
Sesame Avatar asked Jul 26 '10 23:07

Sesame


4 Answers

Yes, there is native support in SSMS 2008 on, without any addins. The regions are defined by:

  1. From first GO command to next GO command.
  2. Statements between BEGIN – END, BEGIN TRY – END TRY, BEGIN CATCH – END CATCH
  3. Multiline statements

See examples here: http://blog.sqlauthority.com/2009/06/28/sql-server-2008-management-studio-new-features-2/

like image 80
sql xdetails Avatar answered Nov 01 '22 17:11

sql xdetails


There is an add-in for SSMS called SSMS Tools Pack. It lets you use #region / #endregion http://www.ssmstoolspack.com/Features?f=9

like image 36
Carlos Muñoz Avatar answered Nov 01 '22 15:11

Carlos Muñoz


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.

like image 2
Andrei Rantsevich Avatar answered Nov 01 '22 16:11

Andrei Rantsevich


I have just been hacking the begin, end to create regions as shown below:

begin--region Getting top 5 Employee records
    select top 5 * from dbo.Employee order by Salary;
end--region Getting top 5 Employee records

I always make sure to put the --region beside the begin and end so they stand out from real begin and end blocks. For example:

if (1=1)
begin
    begin--region Getting top 5 Employee records
        select top 5 * from dbo.Employee order by Salary;
    end--region Getting top 5 Employee records
end
like image 1
CodingYoshi Avatar answered Nov 01 '22 17:11

CodingYoshi