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 thou开发者_高级运维ghts?
Yes, there is native support in SSMS 2008 on, without any addins. The regions are defined by:
- From first GO command to next GO command.
- Statements between BEGIN – END, BEGIN TRY – END TRY, BEGIN CATCH – END CATCH
- Multiline statements
See examples here: http://blog.sqlauthority.com/2009/06/28/sql-server-2008-management-studio-new-features-2/
There is an add-in for SSMS called SSMS Tools Pack. It lets you use #region / #endregion http://www.ssmstoolspack.com/Features?f=9
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.
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
No there's not. It only is done at the statement level.
精彩评论