gpt4 book ai didi

sql - MS-SQL 表设计器中方括号 [] 的含义?

转载 作者:行者123 更新时间:2023-12-01 21:43:15 24 4
gpt4 key购买 nike

我有一个包含现有记录的现有数据库的副本。当我与表格设计器一起玩时,注意到一些列名称周围有 [] 。它们似乎都是任意类型的(float、datetime、netext、nvarchar 等),并且列属性中没有任何内容可以摆脱 []。我尝试重命名删除 [],但一旦退出编辑它就会重新出现。

根据this帖子,它是 xml 列的关键字列吗?但这些列都不是 xml 列。有人可以向 ms-sql 新手解释一下这样做的目的吗?谢谢

最佳答案

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

一些用户也喜欢使用方括号,即使它们不是必需的。

来自MSDN :

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.

关于sql - MS-SQL 表设计器中方括号 [] 的含义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9917196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com