Minor

Local variable and parameter names should comply with a naming convention

Description

    The "Local variable and parameter names should comply with a naming convention" code rule states that all local variables and parameters used in a SQL Server database should be named in accordance with a specific naming convention. This helps to ensure better readability and maintainability of the code. For instance, a naming convention might require that all local variables start with a lowercase letter, and all parameters start with an uppercase letter. Additionally, the naming convention might also include rules for how to name objects, such as tables, stored procedures, etc. By following a naming convention, it becomes easier for developers to quickly identify the purpose of a variable or parameter.

Key Benefits

  • Consistency: Using a naming convention helps ensure that all variables and parameters have a consistent naming structure.
  • Readability: Following a naming convention makes it easier to read and understand code, as it is easier to identify variables and parameters.
  • Ease of Maintenance: Using a naming convention makes it easier to maintain code, as it is easier to identify and modify variables and parameters.

 

Non-compliant Code Example

CREATE Procedure [DATA].sp_GetFullname
@fname nvarchar(10),
@mname nvarchar(10),
@@lname nvarchar(10)  --Non compliant code (Procedure parameter name is not comply with a naming convention)
AS
BEGIN
    select [DATA].[GetFullName](@fname, @mname)
END

Compliant Code Example

CREATE Procedure [DATA].sp_GetFullname
@fname nvarchar(10),
@lname nvarchar(10)  --Compliant code (Procedure parameter name is comply with a naming convention)
AS
BEGIN
    select [DATA].[GetFullName](@fname, @lname)
END
Visual Expert 2023
 VETSQLRULE54