Skip to content

SA0062A : Check all Functions in the current database for following specified naming convention

Use standardized naming conventions for functions to avoid confusion and ensure clarity in multi-developer environments.

Naming conventions are crucial for maintaining organized and readable databases in SQL Server. When function names do not adhere to a standardized pattern, they can lead to confusion and misinterpretation, particularly in environments with multiple developers. Adhering to proper naming conventions helps in maintaining code clarity and improves teamwork efficiency.

For example:

-- Example of inconsistent naming conventions
CREATE FUNCTION calcTotal() RETURNS INT AS BEGIN
RETURN 1; -- Static example
END
CREATE FUNCTION totalCalc() RETURNS INT AS BEGIN
RETURN 2; -- Static example
END

The above functions have similar purposes but differing names, which can cause confusion. Ensuring consistent naming patterns such as prefixing function names with their return type or functionality can enhance clarity.

  • Lack of naming consistency makes identifying function purposes and uses more challenging.

  • Deviations from naming conventions can complicate maintenance and troubleshooting efforts.

Ensure that your SQL Server function names follow a consistent naming convention to maintain code clarity and teamwork efficiency.

Follow these steps to address the issue:

1.Review the current function names in your SQL Server database. Identify any that do not follow the agreed-upon naming convention. For inline identification, inspect function names using SELECT name FROM sys.objects WHERE type = 'FN'; in your SQL Server Management Studio (SSMS).

2.Determine a standardized naming convention for your functions. This could include standard prefixes or suffixes that indicate the function’s purpose or return type, such as fn_ for functions.

3.Rename the identified functions to align with the naming convention. Use the sp_rename system stored procedure for renaming. Ensure you update any application or scripts that use the renamed functions.

For example:

-- Renaming a function to adhere to naming conventions
EXEC sp_rename 'calcTotal', 'fn_CalculateTotal';
EXEC sp_rename 'totalCalc', 'fn_TotalCalculation';

The rule has a ContextOnly scope and is applied only on current server and database schema.

Name Description Default Value
ScalarFunctionNamePattern Scalar function name pattern. regexp:ufn[A-Z][A-Za-z1-9_]+
ScalarFunctionSchemaQualifiedNamePattern Scalar function schema qualified name pattern. -
TableValuedFunctionNamePattern Table-valued function name pattern. regexp:ufn[A-Z][A-Za-z1-9_]+
TableValuedFunctionSchemaQualifiedNamePattern Table-valued function schema qualified name pattern. -
AggregateFunctionNamePattern Aggregate function name pattern. regexp:ufn[A-Z][A-Za-z1-9_]+
AggregateFunctionSchemaQualifiedNamePattern Aggregate function schema qualified name pattern. -
PartitionFunctionNamePattern Partition function name pattern. regexp:[A-Z][A-Za-z1-9_]+PFN

The rule requires Analysis Context. If context is missing, the rule will be skipped during analysis.

8 minutes per issue.

Naming Rules, Code Smells

There is no additional info for this rule.

Analysis Rules