Skip to content

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:

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

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 name
CREATE 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.

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.

3 minutes per issue.

Design Rules, Naming Rules, Deprecated Features, Code Smells

Deprecated Database Engine Features

Discontinued Database Engine Functionality

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 g
WHERE
g.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

Analysis Rules