The database object name is known as its identifier. Everything in Microsoft® SQL Server™ can have an identifier. Servers, databases, and database objects such as tables, views, columns, indexes, triggers, procedures, constraints, rules, and so on can have identifiers. Identifiers are required for most objects, but are optional for some objects, such as constraints.
An object identifier is created when the object is defined. The identifier is then used to reference the object. For example, this statement creates a table with the identifier TableX, and two columns with the identifiers KeyCol and Description:
CREATE TABLE TableX
(KeyCol INT PRIMARY KEY, Description NVARCHAR(80))
This table also has an unnamed constraint. The PRIMARY KEY constraint has no identifier.
There are two classes of identifiers:
Regular identifiers
Conform to the rules for the format of identifiers. Regular identifiers are not delimited when used in Transact-SQL statements.
SELECT *
FROM TableX
WHERE KeyCol = 124
Delimited identifiers
Are enclosed in double quotation marks (") or brackets ([ ]). Identifiers that comply with the rules for the format of identifiers may or may not be delimited.
SELECT *
FROM [TableX] --Delimiter is optional.
WHERE [KeyCol] = 124 --Delimiter is optional.
Identifiers that do not comply with all of the rules for identifiers must be delimited in a Transact-SQL statement.
SELECT *
FROM [My Table] --Identifier contains a space and uses a reserved keyword.
WHERE [order] = 10 --Identifier is a reserved keyword.
Both regular and delimited identifiers must contain from 1 through 128 characters. For local temporary tables, the identifier can have a maximum of 116 characters.
The rules for the format of regular identifiers are dependent on the database compatibility level, which can be set with sp_dbcmptlevel. For more information, see sp_dbcmptlevel. When the compatibility level is 80, the rules are:
Certain symbols at the beginning of an identifier have special meaning in SQL Server. An identifier beginning with the "at" sign denotes a local variable or parameter. An identifier beginning with a number sign denotes a temporary table or procedure. An identifier beginning with double number signs (##) denotes a global temporary object.
Some Transact-SQL functions have names that start with double at signs (@@). To avoid confusion with these functions, it is recommended that you do not use names that start with @@.
When used in Transact-SQL statements, identifiers that fail to comply with these rules must be delimited by double quotation marks or brackets.