Click or drag to resize

SA0184 : Redundant pairs of parentheses can be removed

The topic describes the SA0184 analysis rule.

Message

Redundant pairs of parentheses can be removed

Description

The rule reports logical and arithmetic expressions, and queries for being enclosed in redundant pairs of parentheses.

The parentheses, which are not used to specify the desired order of operations could be misleading and should be removed.

Scope

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

Parameters
NameDescriptionDefault 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

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Design Rules, New Rules

Additional Information

There is no additional info for this rule.

Example Test Script
 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

Analysis Results

 MessageLineColumn
1SA0184 : Redundant pairs of parentheses can be removed.1548
2SA0184 : Redundant pairs of parentheses can be removed.188
3SA0184 : Redundant pairs of parentheses can be removed.2215
4SA0184 : Redundant pairs of parentheses can be removed.2019
5SA0184 : Redundant pairs of parentheses can be removed.2029
6SA0184 : Redundant pairs of parentheses can be removed.2317
7SA0184 : Redundant pairs of parentheses can be removed.299
8SA0184 : Redundant pairs of parentheses can be removed.303
9SA0184 : Redundant pairs of parentheses can be removed.3017
10SA0184 : Redundant pairs of parentheses can be removed.3511
...
12SA0184 : Redundant pairs of parentheses can be removed.4116
13SA0184 : Redundant pairs of parentheses can be removed.4132
See Also

Other Resources