Home

Redundant pairs of parentheses should be removed

Description

    The "Redundant pairs of parentheses should be removed" SQL Server code rule aims to reduce unnecessary complexity in code and improve readability by removing redundant parentheses. This rule applies to all SQL Server code, including SELECT, INSERT, UPDATE, and DELETE statements. Redundant parentheses are those that are not required to determine the order of operations in the code. Removing these parentheses can help make the code easier to read and understand, as well as reducing the amount of code needed to accomplish a given task. Additionally, removing redundant parentheses can help improve the performance of the code by reducing the amount of time needed to parse the code.

Key Benefits

  • Reduce complexity: Removing redundant pairs of parentheses can help reduce the complexity of a codebase and make it easier to read and understand.
  • Improve performance: By removing unnecessary parentheses, code execution can be improved, resulting in faster performance.
  • Reduce errors: Removing redundant pairs of parentheses can help reduce the chances of errors occurring due to incorrect syntax or logic.

 

Non-compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF ((@Number > 100))   --Non compliant code (Conditional with redundant pairs of parentheses)
    PRINT 'The number is large.';  
ELSE   
    BEGIN  
        IF ((@Number < 10) AND (@Number > 0))  --Non compliant code (Conditional with redundant pairs of parentheses)
            PRINT 'The number is small.';  
        ELSE  
            PRINT 'The number is medium.';  
    END ;  
GO 

Compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF (@Number > 100)   --Compliant code (Conditional without redundant pairs of parentheses)
    PRINT 'The number is large.';  
ELSE   
    BEGIN  
        IF (@Number < 10) AND (@Number > 0)  --Compliant code (Conditional without redundant pairs of parentheses)
            PRINT 'The number is small.';  
        ELSE  
            PRINT 'The number is medium.';  
    END ;  
GO 
Visual Expert 2024
 VETSQLRULE41