Bug

Code Rules in Bug category

Category Severity Name Description
Bug Major All branches in a conditional structure should not have exactly the same implementation

The rule "All branches in a conditional structure should not have exactly the same implementation" states that when a conditional structure is used in SQL Server code, the branches should not have identical implementations. This means that each branch should have a unique implementation that is tailored to the specific conditions of that branch. This helps to ensure that the code is efficient and that it produces the desired results. Additionally, this rule helps to prevent potential errors or unexpected behavior that could occur if the same implementation were used for all branches.

Bug Critical CASE input expressions should be invariant

The CASE input expressions should be invariant rule states that when using the CASE statement in SQL Server, the input expressions should remain the same throughout the statement. This means that any variables used in the input expressions should not be changed or modified, as this could lead to unexpected results. This rule is important to ensure that the CASE statement produces the expected output.

Bug Critical DELETE and UPDATE statements should contain WHERE clauses

The DELETE and UPDATE statements should contain WHERE clauses in order to limit the scope of the changes to only the rows that meet the specified criteria. This is important to ensure that the changes are only applied to the intended rows and that no unintended changes are made. Without a WHERE clause, the entire table or set of records will be affected, which could have serious consequences. Therefore, it is important to always include a WHERE clause when using DELETE and UPDATE statements in order to limit the scope of the changes.

Bug Major Identical expressions should not be used on both sides of a binary operator

This rule states that when using a binary operator (such as an equals sign or a less than sign) the same expression should not be used on both sides of the operator. For example, in the following statement:

x = x

The expression "x" is used on both sides of the equals sign, which is not allowed according to this rule. Instead, the statement should be written as:

x = 5

or some other expression that is not the same on both sides of the equals sign.

Bug Major Jump statements should not be followed by dead code

The "Jump statements should not be followed by dead code" rule states that any statement that causes the execution to jump to another part of the code, such as a loop or an IF statement, should not be followed by any code that will not be executed. This is because such code is unnecessary and can lead to confusion and errors when debugging or maintaining the code. This rule helps ensure that the code is clean and efficient, and that any code that is written is actually being used.

Bug Major Loops with at most one iteration should be refactored

The "Loops with at most one iteration should be refactored" code rule for SQL Server suggests that any loop that has a single iteration should be refactored into a simpler code structure. This is because, in most cases, a loop with a single iteration can be replaced with a simpler code structure that can be more easily understood and maintained. By refactoring the code, it can improve the readability and maintainability of the code and reduce the risk of errors. Additionally, it can improve the performance of the code by reducing the amount of unnecessary looping operations.

Bug Major NULL should not be compared directly

The SQL Server code rule "NULL should not be compared directly" means that when comparing two values, an explicit comparison operator should be used instead of just comparing the values directly. This is because a direct comparison of two NULL values will always return true, which may not be the desired result. Instead, an explicit comparison operator should be used to ensure the comparison is done correctly. For example, instead of writing "IF x = NULL", the code should be written as "IF x IS NULL".

Bug Critical Nullable subqueries should not be used in NOT IN conditions

This rule states that subqueries that produce NULL values should not be used in NOT IN conditions. This is because when a subquery produces a NULL value, it is not considered an element of the set that is being compared, and thus the comparison will always return false. This can lead to unexpected results, and should be avoided. To ensure that the comparison works as expected, use a NOT EXISTS condition instead.

Bug Major Output parameters should be assigned

The "Output parameters should be assigned" rule states that any output parameters declared in a SQL Server stored procedure should be assigned a value before the procedure is executed. This ensures that the output parameters are not left unassigned, which can lead to unexpected behavior and errors. Additionally, this rule helps to make the code more readable and maintainable by making it clear which output parameters are being used and what values they should be assigned.

Bug Major Queries that use TOP should have an ORDER BY

The SQL Server code rule "Queries that use TOP should have an ORDER BY" requires that when using the TOP clause in a query, an ORDER BY clause must also be included. This ensures that the results of the query are in a predictable order. Without an ORDER BY clause, the order of the results is not guaranteed. This rule is in place to ensure that the results of the query are consistent and predictable.

Bug Major Related IF/ELSE IF statements and WHEN clauses in a CASE should not have the same condition

The "Related IF/ELSE IF statements and WHEN clauses in a CASE should not have the same condition" SQL Server code rule states that when using IF/ELSE IF statements and WHEN clauses in a CASE statement, the conditions should be different. This ensures that the correct logic is being used and that the code is not redundant. If the same condition is used for multiple IF/ELSE IF statements or WHEN clauses, then the code will not be as efficient as it could be and could lead to unexpected results. It is important to ensure that the conditions are different for each IF/ELSE IF statement and WHEN clause in order to ensure that the code is efficient and that the results are as expected.

Bug Critical Syntax Errors

The SQL Server Code Rule "Syntax Errors" checks for syntax errors in Transact-SQL code. It ensures that the code is syntactically correct and that it can be parsed and compiled without any errors. This rule helps identify any syntax errors that may exist in the code and provides suggestions on how to fix them. It also flags any code that may be syntactically correct but may not produce the expected results. This rule is useful for ensuring that the code runs as expected and does not cause any unexpected errors.

Bug Critical The number of variables in a FETCH statement should match the number of columns in the cursor

The FETCH statement in SQL Server should have the same number of variables as the number of columns in the cursor. This ensures that the correct data is retrieved from the database. If the number of variables does not match the number of columns, then the query will fail. This rule helps to ensure that the data being retrieved is accurate and complete.

Bug Major Unary prefix operators should not be repeated

The rule "Unary prefix operators should not be repeated" states that unary prefix operators should not be used more than once in a statement. Unary prefix operators are operators that operate on one value, such as the minus sign (-) or the plus sign (+). Repeating these operators can lead to confusion and errors in the code, and should be avoided.

Bug Major Variables should not be self-assigned

The rule "Variables should not be self-assigned" states that variables should not be assigned a value that is equal to its own existing value. This rule is important when writing SQL Server code, as assigning a variable to itself can lead to unexpected results. Self-assigning variables can also lead to poor performance, as the server will need to evaluate and assign the same value multiple times. In order to ensure optimal performance and accuracy, variables should only be assigned values that differ from their existing value.

Bug Major WHERE clause conditions should not be contradictory

This SQL Server code rule states that conditions in the WHERE clause of a query should not be contradictory. This means that the conditions should not be mutually exclusive or logically impossible. Contradictory conditions can lead to incorrect results and should be avoided.

For example, if a query contains the following WHERE clause:

WHERE age > 18 AND age < 18

This would be considered a contradictory condition as it is logically impossible for a person to be both older than 18 and younger than 18 at the same time. Therefore, this condition should be avoided.

Bug Major WHERE clauses should not contain redundant conditions

The "WHERE clauses should not contain redundant conditions" code rule states that WHERE clauses should not contain conditions that are unnecessary or redundant. This means that the WHERE clause should only contain conditions that are necessary for the query to return the desired results. Redundant conditions can lead to inefficient query execution as the engine will need to process them unnecessarily. Furthermore, redundant conditions can lead to incorrect query results if the conditions are not logically equivalent. It is therefore important to ensure that the WHERE clause contains only the necessary conditions.