Share via


SR0011: Avoid using special characters in object names

RuleId

SR0011

Category

Microsoft.Naming

Breaking Change

Breaking

Cause

The name of at least one database object contains at least one special character.

Rule Description

If you name a database object by using any character in the following table, you make it more difficult not only to reference that object but also to read code that contains the name of that object:

Character

Description

Whitespace character

[

Left square bracket

]

Right square bracket

'

Single quotation mark

"

Double quotation mark

How to Fix Violations

To resolve this issue, you must remove all special characters from the object name. If the object is referenced in other locations in your database project (such as in database unit tests), you should use database refactoring to update the references. For more information, see Rename All References to a Database Object.

When to Suppress Warnings

You might have to suppress these warnings if one or more other applications reference the database object and you cannot change the applications.

Example

In the first example, a table contains a column that has a special character in its name. In the second example, the name does not contain a special character.

CREATE TABLE [dbo].[TableWithProblemColumn]
( 
[ID] INT NOT NULL IDENTITY(0, 1), 
[Small'String] VARCHAR(10)
)
ON [PRIMARY]

CREATE TABLE [dbo].[FixedTable]
( 
[ID] INT NOT NULL IDENTITY(0, 1), 
[SmallString] VARCHAR(10)
)
ON [PRIMARY]

SR0012: Avoid using reserved words for type names

SR0016: Avoid using sp_ as a prefix for stored procedures

See Also

Concepts

Improving Database Code with Static Analysis