SA0159 : Deprecated use of object name containing only # characters
Introduction
Section titled “Introduction”Improper naming of database objects such as tables, views, functions, or triggers can lead to confusion and complicate maintenance tasks.
Description
Section titled “Description”In T-SQL code and when working with SQL Server, naming conventions are crucial for maintaining clarity and consistency across database systems. An object name that consists solely of a string of # characters can lead to confusion during development and management processes. It is important to use meaningful and descriptive names for database objects to improve readability and maintenance.
For example:
-- Example of a problematic object nameCREATE TABLE ##### (ID INT PRIMARY KEY);This query illustrates an issue where a table is named using only # characters. It lacks clarity and makes understanding the purpose of the table difficult for anyone reviewing the code. Adopting such naming practices can obscure the intentions behind the design and significantly complicate debugging and future enhancements.
-
Leads to confusion and errors due to lack of descriptive identifiers.
-
Complicates collaboration and code handover, as the purpose of the object isn’t immediately clear.
How to fix
Section titled “How to fix”Ensure that database object names are clear and descriptive to improve readability and maintenance.
Follow these steps to address the issue:
1.Identify the database objects (like tables, views, functions, or triggers) that have names consisting solely of # characters.
2.Rename these objects to include at least one meaningful character that describes their purpose. For instance, use a prefix indicative of the object type, like tbl for tables or fn for functions, followed by a descriptive name.
3.Update any dependent scripts or code that reference the renamed objects to ensure they continue to function correctly.
For example:
-- Renaming a table with a descriptive nameCREATE TABLE SalesData ( ID INT PRIMARY KEY, SalesAmount DECIMAL(10, 2), SalesDate DATE);The rule has a Batch scope and is applied only on the SQL script.
Parameters
Section titled “Parameters”Rule has no parameters.
Remarks
Section titled “Remarks”The rule does not need Analysis Context or SQL Connection.
Effort To Fix
Section titled “Effort To Fix”3 minutes per issue.
Categories
Section titled “Categories”Design Rules, Naming Rules, Deprecated Features, Code Smells
Additional Information
Section titled “Additional Information”Deprecated Database Engine Features
Discontinued Database Engine Functionality
Example Test SQL
Section titled “Example Test SQL”CREATE TABLE #(GreetingId INT IDENTITY (1,1) PRIMARY KEY,Message nvarchar(255) NOT NULL,)CREATE TABLE ##(GreetingId INT IDENTITY (1,1) PRIMARY KEY,Message nvarchar(255) NOT NULL,)CREATE TABLE #table1(GreetingId INT IDENTITY (1,1) PRIMARY KEY,Message nvarchar(255) NOT NULL,)
SELECT * INTO ##### FROM Test.Greeting gWHEREg.Message like 'Hello%'Analysis Results
Section titled “Analysis Results”| Message | Line | Column | |
|---|---|---|---|
| 1 | SA0159 : Deprecated use of object name containing only # characters. | 1 | 13 |
| 2 | SA0159 : Deprecated use of object name containing only # characters. | 6 | 13 |
| 3 | SA0159 : Deprecated use of object name containing only # characters. | 17 | 14 |