Home

Empty statements should be removed

Description

    The Empty Statements should be removed code rule in SQL Server states that any empty statements in a SQL script should be removed. Empty statements are those that do not contain any content and are not required for the code to execute. Examples of empty statements include blank lines, comments, and empty IF, WHILE, and BEGIN/END blocks. Removing empty statements can help reduce the complexity of the code and make it easier to read and understand. Additionally, it can help reduce the number of errors that may occur during execution.

Key Benefits

  • Reduced complexity - Removing empty statements can help reduce the complexity of code.
  • Improved readability - Removing empty statements can improve the readability of code.
  • Less code to maintain - Removing empty statements can reduce the amount of code that needs to be maintained.

 

Non-compliant Code Example

DECLARE @Number int;;   --Non compliant code (Empty statements)
SET @Number = 50;   ;  --Non compliant code (Empty statements)
IF @Number > 100 
BEGIN
    Select * From Employee Where id < @Number;
    PRINT 'The number is positive.'; 
END

Compliant Code Example

DECLARE @Number int;   --Compliant code
SET @Number = 50;   --Compliant code
IF @Number > 100 
BEGIN
    Select * From Employee Where id < @Number;
    PRINT 'The number is positive.'; 
END
Visual Expert 2024
 VETSQLRULE55