Major

Code Rules in Major Severity

Category Severity Name Description
Maintainability Major @@IDENTITY should not be used

The code rule "@@IDENTITY should not be used" states that the global variable @@IDENTITY should not be used in SQL Server code. This variable is often used to retrieve the last identity value generated in the current session, but it can be unreliable and lead to unexpected results. Instead, the SCOPE_IDENTITY() function should be used to retrieve the last identity value generated in the current scope.

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.

Maintainability Major ANSI_NULLS, ANSI_PADDING and CONCAT_NULL_YIELDS_NULL should not be configured The ANSI_NULLS, ANSI_PADDING and CONCAT_NULL_YIELDS_NULL code rules indicate that the SQL Server should not be configured to use these settings. ANSI_NULLS defines how to handle comparisons involving NULL values. When set to ON, two NULL values are considered equal. When set to OFF, two NULL values are considered unequal. ANSI_PADDING defines how to handle trailing spaces in character data. When set to ON, trailing spaces are retained. When set to OFF, trailing spaces are removed. CONCAT_NULL_YIELDS_NULL defines how to handle the concatenation of NULL values. When set to ON, the result of the concatenation is NULL. When set to OFF, the result of the concatenation is an empty string. For optimal performance, it is recommended that these settings not be configured as they can lead to unexpected results and can affect the performance of the SQL Server.
Maintainability Major CASE expressions should not have too many WHEN clauses

The "CASE expressions should not have too many WHEN clauses" rule states that when using CASE expressions in SQL Server, the number of WHEN clauses should be limited to improve readability and maintainability of the code. Having too many WHEN clauses can make the code difficult to read and understand, and can also lead to potential performance issues. This rule encourages developers to use simpler alternatives such as IF/ELSE or WHILE loops when multiple WHEN clauses are needed. Additionally, it is recommended to use meaningful names for each WHEN clause to make the code easier to read and maintain.

Maintainability Major COALESCE, IIF, and CASE input expressions should not contain subqueries

This rule states that when using the COALESCE, IIF, and CASE functions in SQL Server, the input expressions should not contain subqueries. Subqueries should not be used because they can cause performance issues, as well as make the code more difficult to read and maintain. Instead, use a simple expression or variable.

Maintainability Major Collapsible if statements should be merged

The "Collapsible if statements should be merged" code rule states that when multiple if statements are logically connected, they should be merged into a single if statement to improve readability and maintainability of the code. This helps to reduce the complexity of the code and make it easier to understand what the code is doing. Additionally, merging the if statements can help to reduce the number of lines of code, making it easier to debug and maintain.

Maintainability Major Column names should be used in an ORDER BY clause

This rule states that when using the ORDER BY clause in SQL Server, column names should be used instead of column numbers. This ensures that the ordering of the results is based on the columns that are specified, and not on the order of the columns in the table.

For example, if you wanted to order a table by the columns "FirstName" and "LastName", you should use the following code:

ORDER BY FirstName, LastName

Instead of using the column numbers, which may change in the future, this rule ensures that the ordering of the results is always based on the specified columns.

Maintainability Major Columns to be read with a SELECT statement should be clearly defined

This SQL Server code rule states that when using a SELECT statement, the columns that are to be read should be explicitly defined. This helps to ensure that only the data that is required is read, and that the query is more efficient. Additionally, it ensures that the query is more readable, as the columns that are being read are clearly defined.

Maintainability Major Deprecated features should not be used

The SqlServer code rule "Deprecated features should not be used" states that any deprecated features of the SqlServer platform should not be used in code. Deprecated features are features that have been superseded by newer versions or features, and are no longer supported by the platform. Using deprecated features can lead to security vulnerabilities, performance issues, and compatibility problems, so it is important to avoid using them in code. It is also important to ensure that any code written is up to date with the latest version of SqlServer, as new features may be available that can improve the code's performance or security.

Maintainability Major Deprecated system tables and views should not be used

The rule "Deprecated system tables and views should not be used" states that any system tables or views that have been marked as deprecated, or are no longer supported, should not be used by developers when writing SQL Server code. This rule is important because deprecated system tables and views can contain outdated or inaccurate data, and using them in code can lead to unexpected results or errors. Additionally, using deprecated system tables and views can also cause performance issues if the code is not optimized properly.

Maintainability Major Duplicate values should not be passed as arguments

The "Duplicate values should not be passed as arguments" SQL Server code rule states that when passing arguments to a stored procedure or function, any duplicate values should not be included. This is to avoid any potential issues with the code, such as an unexpected result or an error. By not including duplicate values, the code will be more reliable and efficient. In some cases, it may also be necessary to check the data type of the argument to ensure that they are compatible with the data type of the parameter. This code rule helps to ensure that the code is robust and reliable.

Maintainability Major Files should not have too many lines of code

This rule states that files should not contain an excessive amount of code. This is to ensure that files are easier to read and understand. It is also important to keep code organized and manageable. Too much code can lead to confusion and difficulty in debugging and maintaining the code. This rule helps to keep code organized and maintainable. It is important to keep the code as concise as possible and to split up large files into smaller, more manageable chunks. This will ensure that the code is easier to read and understand.

Maintainability Major Function and procedure names should comply with a naming convention

The "Function and Procedure Names Should Comply with a Naming Convention" rule states that all functions and procedures within a SQL Server database should be named according to a predetermined naming convention. This naming convention should be consistent across all databases and should be used to make it easier for developers and administrators to identify the purpose of a particular function or procedure. This naming convention should also be documented and used to ensure that all functions and procedures are consistently named.

Maintainability Major Functions and procedures should not have too many parameters

The code rule "Functions and procedures should not have too many parameters" states that functions and procedures should be kept as simple as possible, with a limited number of parameters. Having too many parameters can make the code difficult to read, understand, and maintain. It can also lead to increased complexity and a greater chance of errors. When designing functions and procedures, it is important to keep the number of parameters to a minimum, and to use descriptive names for each parameter. This will make the code easier to read and maintain, and will reduce the chances of errors.

Maintainability Major Functions and stored procedure should not have too many lines of code

The SQL Server code rule "Functions and stored procedures should not have too many lines of code" is a best practice for developers to follow when creating functions and stored procedures. This rule is designed to help maintain code readability and reduce the complexity of the code. It is important to keep the code concise and easy to understand, as too many lines of code can lead to confusion and difficulty in debugging. Additionally, too much code can lead to an increase in the amount of time it takes to execute the code. By following this rule, developers can ensure their code is efficient and maintainable.

Maintainability Major GOTO statements should not be used

The GOTO statements should not be used rule states that GOTO statements should not be used when writing SQL Server code. GOTO statements are a type of unconditional jump which can make code difficult to read and maintain. They should be avoided in favor of more structured programming techniques, such as using IF-ELSE statements. Using GOTO statements can also lead to unintended results, as the code may not execute as intended. This rule encourages developers to use more structured programming techniques to ensure that code is more readable and maintainable.

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.

Maintainability Major LIKE clauses should not start with wildcard characters

The rule "LIKE clauses should not start with wildcard characters" means that when using the LIKE clause in SQL Server, wildcard characters such as % and _ should not be used as the first character in the clause. This is because wildcards are used to match any character or string of characters, so starting with one will cause the query to return too many results. This can cause performance issues and make it difficult to interpret the results.

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.

Maintainability Major Multiline blocks should be enclosed in BEGIN...END blocks

The Multiline blocks should be enclosed in BEGIN...END blocks rule states that any SQL Server code containing multiple lines of code should be enclosed with a BEGIN...END block. This is to ensure that all lines of code are executed together as a single unit and that any errors that occur are handled in the same way. It also helps to make code easier to read and debug.

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 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.

Maintainability Major Queries should not join too many tables

The "Queries should not join too many tables" code rule states that when writing SQL queries, it is important to limit the number of tables that are joined in the query. Joining too many tables can lead to complex queries that are difficult to read, debug, and maintain. Additionally, joining too many tables can lead to decreased performance, as the query optimizer must process more data to return the desired result set. Therefore, it is recommended to limit the number of tables joined in a query to improve readability and performance.

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.

Maintainability Major Redundant pairs of parentheses should be removed

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.

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.

Maintainability Major Statements should be on separate lines

The "Statements should be on separate lines" code rule for SQL Server means that each individual statement should be written on its own line. This helps to improve readability and maintainability of code. It also helps to ensure that any changes to the code are easier to identify and modify, as each statement is clearly separated from the other statements. This rule helps to ensure that SQL code is easier to read and understand, and can help to reduce the chances of errors or typos occurring.

Maintainability Major Track lack of SQL Server session configuration The Track lack of SQL Server session configuration code rule checks whether SQL Server session settings are configured correctly. It will detect any lack of configuration that could lead to degraded performance or security issues. This code rule is part of the Microsoft Security Code Analysis extension and is used to identify any configuration settings that are not properly set. The rule checks for the following session settings: - Max Degree of Parallelism - Cost Threshold for Parallelism - Remote Query Timeout - Lock Timeout - Deadlock Priority - Query Wait - Security Settings The rule will detect any lack of configuration that could lead to degraded performance or security issues. It is important to ensure that these settings are properly configured to ensure optimal performance and security.
Maintainability Major Track uses of FIXME tags The Track uses of FIXME tags code rule tracks the use of FIXME tags in SQL Server code. FIXME tags are used to indicate that certain portions of code need to be addressed or fixed. The rule scans the code for any occurrences of the tag and reports them as potential problems. This rule helps developers to identify areas of code that need to be addressed before deployment.
Maintainability Major Two branches in a conditional structure should not have exactly the same implementation

The "Two branches in a conditional structure should not have exactly the same implementation" rule for SQL Server code states that when a conditional structure is used, such as an "IF/ELSE" statement, the two branches must have different implementations. This rule is important for ensuring that the code is optimized and that redundant code is avoided. The two branches should be distinct and have different implementations to ensure that the code is efficient and maintainable.

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.

Maintainability Major Unused procedure and function parameters should be removed

This rule states that any procedure or function parameters that are not used within the code should be removed. This helps to reduce unnecessary clutter and complexity in the code, while also making it easier to read and understand. Additionally, it can help to ensure that the code is performing optimally by eliminating any unused parameters that may be slowing down the execution time. Removing unused parameters can also help to reduce the risk of potential security vulnerabilities, as any potential attackers would have fewer parameters to exploit.

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.

Maintainability Major WHEN clauses should not have too many lines of code The WHEN clauses should not have too many lines of code rule is a best practice for SQL Server code. This rule states that when writing a SQL Server query, each WHEN clause should contain no more than a few lines of code. This will help to improve readability and reduce complexity, while also making it easier to debug and maintain the query. Additionally, having too many lines of code in a WHEN clause can lead to performance issues.
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.