SA0159 : Deprecated use of object name containing only # characters |
![]() |
Improper naming of database objects such as tables, views, functions, or triggers can lead to confusion and complicate maintenance tasks.

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:
1-- Example of a problematic object name 2CREATE 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.

Ensure that database object names are clear and descriptive to improve readability and maintenance.
Follow these steps to address the issue:
-
Identify the database objects (like tables, views, functions, or triggers) that have names consisting solely of # characters.
-
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.
-
Update any dependent scripts or code that reference the renamed objects to ensure they continue to function correctly.
For example:
1-- Renaming a table with a descriptive name 2CREATE TABLE SalesData ( 3 ID INT PRIMARY KEY, 4 SalesAmount DECIMAL(10, 2), 5 SalesDate DATE 6);

The rule has a Batch scope and is applied only on the SQL script.

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.


Design Rules, Naming Rules, Deprecated Features, Code Smells


SQL
1CREATE TABLE # 2( 3GreetingId INT IDENTITY (1,1) PRIMARY KEY, 4Message nvarchar(255) NOT NULL, 5) 6CREATE TABLE ## 7( 8GreetingId INT IDENTITY (1,1) PRIMARY KEY, 9Message nvarchar(255) NOT NULL, 10) 11CREATE TABLE #table1 12( 13GreetingId INT IDENTITY (1,1) PRIMARY KEY, 14Message nvarchar(255) NOT NULL, 15) 16 17SELECT * INTO ##### FROM Test.Greeting g 18WHERE 19g.Message like 'Hello%' |

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 |
