SA0183 : The commented out code reduces readability and should be deleted |
![]() |
Commented-out code reduces readability and creates maintenance challenges.

Commented-out code blocks containing valid T-SQL statements lead to reduced readability and present potential issues in database scripts. This can complicate understanding for developers working with SQL Server, as discerning active code from inactive code becomes challenging. Moreover, storing unused SQL code in comments is considered a bad practice.
For example:
1-- SELECT * FROM Employees WHERE Department = 'Sales';
In the example above, the query is in a comment block. This practice is problematic because it can clutter the codebase and increase complexity in maintenance. Source control should be used to track changes and access historical code instead.
-
It clutters the codebase, making it harder to distinguish active code from inactive code, which impacts documentation and maintenance.
-
Developers may inadvertently maintain or update commented-out code, leading to wasted effort and confusion.

Remove commented-out code to improve readability and maintainability in your SQL scripts.
Follow these steps to address the issue:
-
Identify all commented-out code blocks within the SQL script using a text editor or SQL Server Management Studio (SSMS).
-
Assess whether the commented-out code is necessary. If the code is required for future use, relocate it to a version control system instead of keeping it in the script.
-
Delete the commented-out code block from the script to enhance readability. Use — or /* */ to comment when providing necessary context or explanations, but avoid storing inactive code.
For example:
1-- Corrected SQL script without commented-out code 2SELECT Name, Position FROM Employees WHERE Department = 'Sales';

The rule has a Batch scope and is applied only on the SQL script.

Name | Description | Default Value |
---|---|---|
MinCommentedBlockLines |
The minimum number of lines a commented block, in order to be considered by the rule. |
2 |

The rule does not need Analysis Context or SQL Connection.


Design Rules, Code Smells

There is no additional info for this rule.

SQL
1CREATE TABLE Test.Greeting 2( 3GreetingId INT IDENTITY (1,1) PRIMARY KEY, 4Message nvarchar(255) NOT NULL, 5) 6 7INSERT INTO Test.Greeting (Message) 8SELECT 'Hello!' 9UNION ALL 10SELECT 'Hi!' 11UNION ALL 12SELECT 'Hello, world!' 13 -- DROP TABLE Test.Greeting 14INSERT INTO Test.Greeting (Message) 15VALUES ('How do yo do?'), 16 ('Good morning!'), -- 1 17--2 18--3 19/* 4 20 5 21 6 22 7 23 8 249*/ 25 26 27 ('Good night!') 28--Delete the steps from the Approval Policy 29DELETE Test.Greeting WHERE GreetingId = 3 30/* 31SELECT 1 * FROM1 zTest.Greeting g 32WHERE 33g.Message like 'Hello%' 34 35DROP TABLE Test.Greeting*/ 36 |

No violations found.
