SA0184 : Redundant pairs of parentheses can be removed |
![]() |
Redundant parentheses in SQL expressions can hinder readability and maintainability, potentially leading to confusion in query interpretation.

Redundant parentheses in SQL expressions can be misleading. Although they often do not affect the execution of queries, they can make the code harder to read and maintain, leading to confusion. This is particularly relevant in SQL Server, where query readability is vital for ongoing maintenance and collaboration among developers.
For example:
1-- Example of a query with redundant parentheses 2SELECT ((column1 + column2) * column3) FROM TableName;
In the above example, the outer parentheses around the arithmetic operation are unnecessary and do not change the evaluation order. This can obscure the logic of the query, especially for complex calculations or conditions.
-
Redundant parentheses can make the query seem more complex than it is, potentially leading to misunderstanding.
-
Unnecessary parentheses may hinder performance tuning and understanding of the intended logic, especially in large and complex queries.


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

Name | Description | Default Value |
---|---|---|
IgnoreArithmeticExpressionMainParentheses |
Specifies whether the main parentheses, which wrap an arithmetic expression to be ignored. |
yes |
IgnoreBooleanExpressionMainParentheses |
Specifies whether the main parentheses, which wrap an logical expression to be ignored. |
yes |

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, world!') 9 10INSERT INTO Test.Greeting (Message) 11VALUES ('How do yo do?'), 12 ('Good morning!'), 13 ('Good night!') 14 15DELETE Test.Greeting WHERE (GreetingId = 3 and (aaa != 0 and ttt = 12) and a <1) or a = 1 16 17select (6/(7/5)*12) + 1 18select ((1 + 2) - 3) * 4 / 5 -(6 /(7/5)*12 ) 19 20SELECT lower('AA'),(g.col1 + (g.col2)) FROM Test.Greeting g 21WHERE 22g.Message like ('Hello%') 23or g.Message in (((((select message from UserMessges))))) 24 25DROP TABLE Test.Greeting 26declare @a int = 5 27 28DECLARE @b INT 29set @b = (@a / 2 + 1); 30IF (@b > 0) AND ((@b+@a > 0)) 31BEGIN 32 print '1' 33END 34 35set @b = (@a / 3 + 1); 36IF (@b > 0) 37BEGIN 38 print '2' 39END 40 41IF (@b > 0) AND (@b-@a > 0) AND (@b-@a) > 0 42BEGIN 43 print '2' 44END |

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, world!') 9 10INSERT INTO Test.Greeting (Message) 11VALUES ('How do yo do?'), 12 ('Good morning!'), 13 ('Good night!') 14 15DELETE Test.Greeting WHERE (GreetingId = 3 and aaa != 0 and ttt = 12 and a <1) or a = 1 16 17select (6/ 7/5*12) + 1 18select ( 1 + 2 - 3) * 4 / 5 -(6 / 7/5*12 ) 19 20SELECT lower('AA'),(g.col1 + g.col2) FROM Test.Greeting g 21WHERE 22g.Message like 'Hello%' 23or g.Message in ( (((select message from UserMessges)))) 24 25DROP TABLE Test.Greeting 26declare @a int = 5 27 28DECLARE @b INT 29set @b = (@a / 2 + 1); 30IF (@b > 0) AND ( @b+@a > 0) 31BEGIN 32 print '1' 33END 34 35set @b = (@a / 3 + 1); 36IF (@b > 0) 37BEGIN 38 print '2' 39END 40 41IF (@b > 0) AND (@b-@a > 0) AND (@b-@a) > 0 42BEGIN 43 print '2' 44END |

Message | Line | Column | |
---|---|---|---|
1 | SA0184 : Redundant pairs of parentheses can be removed. | 15 | 48 |
2 | SA0184 : Redundant pairs of parentheses can be removed. | 17 | 10 |
3 | SA0184 : Redundant pairs of parentheses can be removed. | 18 | 8 |
4 | SA0184 : Redundant pairs of parentheses can be removed. | 18 | 35 |
5 | SA0184 : Redundant pairs of parentheses can be removed. | 22 | 15 |
6 | SA0184 : Redundant pairs of parentheses can be removed. | 20 | 29 |
7 | SA0184 : Redundant pairs of parentheses can be removed. | 23 | 17 |
8 | SA0184 : Redundant pairs of parentheses can be removed. | 30 | 17 |
