Home

Multiple variables should not be declared on the same line

Description

    The code rule "Multiple variables should not be declared on the same line" states that when declaring multiple variables in a SQL Server script, each variable should be declared on a separate line. This helps to improve readability and maintainability of the code, and can also help to detect errors, such as typos, more easily. Additionally, when debugging code, it can be easier to identify which line a specific variable is declared on.

Key Benefits

  • Easier to read: Separating multiple variables on different lines makes it easier to read and understand the code.
  • Fewer mistakes: Declaring multiple variables on the same line can cause errors and mistakes due to incorrect syntax.
  • Better organization: Keeping multiple variables on different lines can help to keep the code organized and easier to manage.

 

Non-compliant Code Example

DECLARE @Number int, @text As varchar(100),@modification as datetime;   --Non compliant code (Multiple variable declared in the same line)
SET @Number = 50;

Compliant Code Example

DECLARE @Number int,
DECLARE @text As varchar(100),
DECLARE @modification as datetime;   --Compliant code (Each variable declared in the new line)
SET @Number = 50;
Visual Expert 2024
 VETSQLRULE52