gpt4 book ai didi

mysql - 使用 SQL 关键字列创建 SQL 表

转载 作者:行者123 更新时间:2023-11-29 01:16:02 25 4
gpt4 key购买 nike

我正在尝试使用名为“lock”的 SQL 关键字列创建 SQL 表,但“lock”似乎是一个 SQL 关键字,工作台认为我想在其中执行“lock”函数。

Create table A(
Lock Varchar(255)
);

*将“Lock”放入方括号中 --> [lock] 对我不起作用。

最佳答案

你应该在保留字两边放回勾号 `:

Create table A(
`Lock` Varchar(255)
);

You can find a good explanation about reserved words and the list of them here.

Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure, partition, tablespace, and other object names are known as identifiers.

If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it.

你应该尽量避免使用这个词,有些人看到这个名字的代码可能会感到困惑。尝试为其添加一个逻辑名称,例如 TabName_Lock

关于mysql - 使用 SQL 关键字列创建 SQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38344653/

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