1

I'm having a problem with organizing SQL scripts that contain more than 10k lines of code.

Let's say there's a declaration of 10 variables:

-- declaration
DECLARE @SaleId1 int
DECLARE @SaleId2 int
DECLARE @SaleId3 int
DECLARE @SaleId4 int
DECLARE @SaleId5 int
DECLARE @SaleId6 int
DECLARE @SaleId7 int
DECLARE @SaleId8 int
DECLARE @SaleId9 int
DECLARE @SaleId10 int

Is there any way to format this code so there would appear minus symbol allowing me to hide all the content and leave just comment?

Something like this:

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Patryk
  • 3,042
  • 11
  • 41
  • 83

4 Answers4

3

In SSMS , goto Tools > Options .

In dialog box find node Transact-SQL > Intellisense

Check Outline Statements option.

Reopen the Sql Script.

Mudassir Hasan
  • 28,083
  • 20
  • 99
  • 133
1

Code regions are not natively supported in SQL Server Management Studio.
In order to organize your code, you have a few options:

  • Refactor to introduce stored procedure and user defined functions
  • Use the “code region hack” defined in this post
  • Install the SSMS Tools Pack which provides advanced format features

Good luck.

Community
  • 1
  • 1
Seymour
  • 7,043
  • 12
  • 44
  • 51
1

Alternatively you can use:

-- declaration
DECLARE @SaleId1 int
,@SaleId2 int
,@SaleId3 int
,@SaleId4 int
,@SaleId5 int
,@SaleId6 int
,@SaleId7 int
,@SaleId8 int
,@SaleId9 int
,@SaleId10 int

enter image description here

Prahalad Gaggar
  • 11,389
  • 16
  • 53
  • 71
1

I have added regions support into my add-in: www.ssmsboost.com (starting from v 2.12) Syntax:

--#region [OptionalName]

--#endregion
Andrei Rantsevich
  • 2,879
  • 20
  • 25