SQL Server identifier

Source: Internet
Author: User

The database name is an identifier, and the table name is also an identifier. in SQL Server, there are two types of identifiers:

There are two types of identifiers:

Regular identifier

Complies with the format rules of identifiers. Do not separate regular identifiers in a Transact-SQL statement.
Select * From tablexwhere keycol = 124

Separator

Enclosed in double quotation marks (") or square brackets. Identifiers that comply with the identifier format rules can be separated or not separated.
Select * from [tablex] -- Delimiter is optional. Where [keycol] = 124 -- Delimiter is optional.

In a Transact-SQL statement, identifiers that do not comply with the rules of all identifiers must be separated.
Select * from [my table] -- identifier contains a space and uses a reserved keyword. Where [order] = 10 -- identifier is a reserved keyword.

The regular and delimiter identifiers must contain 1 to 128 characters. For a local temporary table, the identifier can contain a maximum of 116 characters.

The important difference between the two is that regular identifiers must strictly abide by naming rules, while separated identifiers can not comply with naming rules, as long as they are separated.

identifier format:
1. The identifier must be a character specified in the Unicode 2.0 standard and a number of other language characters. Such as Chinese characters.
2. The characters after the identifier can be (except for condition 1) "_", "@", "#", "$", and numbers.
3. The identifier cannot be a reserved word of transact-SQL.
4. Empty and special characters are not allowed in the identifier.
In addition, some identifiers starting with special characters have specific meanings in SQL Server. For example, the identifier starting with "@" indicates that this is a local variable or a function parameter; the identifier starting with "#" indicates that this is a temporary table or a stored procedure. Starting with "#" indicates that this is a global temporary database object. The global variables of transact-SQL start. An identifier can contain up to 128 characters.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.