Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
627 views
in Technique[技术] by (71.8m points)

tsql - What special characters are allowed in T-SQL column name?

I would like to know what special characters are allowed to be used in column name in T-SQL, MSSQL. So I know I can use letters and numbers, but are the other characters that are available without using brackets [] to refer to this column?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

from MSDN:

The first character must be one of the following:

  • A letter as defined by the Unicode Standard 3.2. The Unicode definition of letters includes Latin characters from a through z, from A through Z, and also letter characters from other languages.
  • The underscore (_), at sign (@), or number sign (#).

Subsequent characters can include the following:

  • Letters as defined in the Unicode Standard 3.2.
  • Decimal numbers from either Basic Latin or other national scripts.
  • The at sign, dollar sign ($), number sign, or underscore.

The identifier must not be a Transact-SQL reserved word. SQL Server reserves both the uppercase and lowercase versions of reserved words.

Embedded spaces or special characters are not allowed.

Supplementary characters are not allowed.

edit

refering to NinthSense: the specs also says:

Certain symbols at the beginning of an identifier have special meaning in SQL Server. A regular identifier that starts with the at sign always denotes a local variable or parameter and cannot be used as the name of any other type of object.

and this statement can be executed without errors:

create table #t (
  #oid int ,
  ?? int,
  ?did varchar(10),
  _data varchar(10)
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...