SA0063A : Check all Views in the current database for following specified naming convention

Use consistent and descriptive naming conventions for views to ensure clarity and maintainability.

Description

Proper naming conventions for views in SQL Server are crucial for maintaining an organized and understandable database schema. Enforcing a consistent naming pattern helps developers and administrators quickly identify the purpose and function of views, reducing confusion and errors.

For example:

SQL
1-- Example of a view with an unclear name
2CREATE VIEW vw_123 AS
3SELECT * FROM Employee;

This example uses a non-descriptive name for the view. Failing to follow naming conventions can lead to several issues, including difficulty in understanding the view’s purpose and the potential for miscommunication among team members.

  • Inconsistent or ambiguous view names can complicate code readability and maintenance.

  • Non-standard naming may lead to challenges in troubleshooting and collaboration.

`

How to fix

Ensure that view names follow established naming conventions to maintain consistency and clarity in your SQL Server database schema.

Follow these steps to address the issue:

  1. Review the current name of the view to determine if it adheres to your organization’s naming conventions. For example, prefixes like vw_ can be used for views.

  2. If the view name does not follow the convention, use the sp_rename system stored procedure to rename the view. The syntax is sp_rename ‘old_name’, ‘new_name’.

  3. Ensure that any dependent objects or procedures are updated to use the new name to prevent errors.

For example:

SQL
1-- Example of renaming a view to follow naming conventions
2EXEC sp_rename 'vw_123', 'vw_EmployeeInfo';

Scope

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

Parameters
Name Description Default Value
NamePattern

View name pattern.

regexp:v[A-Z][A-Za-z1-9_]+

SchemaQualifiedNamePattern

Schema qualified name pattern.

Remarks

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

Effort To Fix
8 minutes per issue.
Categories

Naming Rules, Code Smells

Additional Information

There is no additional info for this rule.

See Also

Other Resources