MS-SQL 表设计器中方括号 [] 的含义? [英] Meaning of square brackets [] in MS-SQL table designer?

查看:24
本文介绍了MS-SQL 表设计器中方括号 [] 的含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含现有记录的现有数据库的副本.当我和表设计师一起玩时,注意到一些列名周围有 [].它们似乎都是任意类型的(float、datetime、netext、nvarchar 等),并且列属性中没有任何内容可以去掉 [].我试图重命名删除 [] 但它在我退出编辑后立即重新出现.

I have a copy of an existing database with existing records. when i was playing around with the table designer and noticed some of the column names have [] around them. they all seem to be arbitrary typed (float, datetime, netext, nvarchar etc) and there is nothing in column properties that gets rid of the []. I tried to rename delete the [] but it reappaears as soon as I exit edit.

根据这篇帖子,它是xml 列的关键字列?但这些列都不是 xml 列.有人会向ms-sql新手解释这个目的吗?谢谢

according to this post, it is a keyword column for xml columns? but none of those columns are xml columns. Would someone kindly explain the purpose of this to a ms-sql newbie? thanks

推荐答案

方括号 [] 用于分隔标识符.如果列名是保留关键字或包含特殊字符(如空格或连字符),则这是必需的.

The square brackets [] are used to delimit identifiers. This is necessary if the column name is a reserved keyword or contains special characters such as a space or hyphen.

有些用户甚至在不需要时也喜欢使用方括号.

Some users also like to use square brackets even when they are not necessary.

来自 MSDN:

分隔标识符

用双引号 (") 或括号 ([ ]) 括起来.符合标识符格式规则的标识符可能会或可能不会被分隔.

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.

不符合所有标识符规则的标识符必须在 Transact-SQL 语句中分隔.

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.

这篇关于MS-SQL 表设计器中方括号 [] 的含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆