SR0012: Avoid using reserved words for type names
RuleId |
SR0012 |
Category |
Microsoft.Naming |
Breaking Change |
Breaking |
Cause
The name of a user-defined type includes a reserved word.
Rule Description
You should avoid using a reserved word as the name of a user-defined type because readers will have a harder time understanding your database code. You can use reserved words in SQL Server as identifiers and object names only if you use delimited identifiers. For a full list of reserved keywords, see this page on the Microsoft Web site: Reserved Keywords (Transact-SQL).
How to Fix Violations
You must rename the user-defined type or object name. You can use database refactoring to easily replace all instances of the name throughout your database project. For more information, see Rename All References to a Database Object.
When to Suppress Warnings
You might need to suppress this warning if an external application that you cannot change references the name.
Example
The first example uses syntax for SQL Server 2000 to show the definition for a user-defined type that will trigger this warning. The second example shows one way to correct the user-defined type and resolve the issue. The third example uses syntax for SQL Server 2005 to show another definition for a user-defined type that will trigger the warning. The fourth example shows one way to correct that user-defined type and resolve the issue.
-- Potential misuse of a keyword as a type name
EXEC sp_addtype N'Alter', N'char(10)',N'not null'
-- Corrected type name
EXEC sp_addtype N'AlterType', N'char(10)',N'not null'
-- Potential misuse of a keyword as a type name
CREATE TYPE Alter
FROM varchar(11) NOT NULL ;
-- Corrected type name
CREATE TYPE AlterType
FROM varchar(11) NOT NULL ;
Related Rules
SR0011: Avoid using special characters in object names
SR0016: Avoid using sp_ as a prefix for stored procedures