Export (0) Print
Expand All

SR0012: Avoid using reserved words for type names

RuleId

SR0012

Category

Microsoft.Naming

Breaking Change

Breaking

The name of a user-defined type includes a reserved word.

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).

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.

You might need to suppress this warning if an external application that you cannot change references the name.

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 ;

Community Additions

ADD
Show:
© 2015 Microsoft