gpt4 book ai didi

sql - mysql 时间戳语法错误

转载 作者:行者123 更新时间:2023-11-29 09:19:23 27 4
gpt4 key购买 nike

我有这段 SQL 正在被输入到 Mysql。

CREATE TABLE pn_history(
member INT,
action INT,
with INT,
timestamp DATETIME,
details VARCHAR(256)
)

但是返回的语法错误。

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'with INT,
timestamp DATETIME,
details VARCHAR(256)
)' at line 4

为什么会失败?

最佳答案

“with”和“timestamp”都是reserved words在 MySQL 中。因此,要使其正常工作,您需要转义每一个:

CREATE TABLE pn_history(
member INT,
action INT,
`with` INT,
`timestamp` DATETIME,
details VARCHAR(256)
)

实际上,您需要考虑更改列的名称 identifiers .

了解更多关于MySQL Reserved Words的信息.

编辑:实际上,TIMESTAMP不是保留字。文档说:

MySQL allows some keywords to be used as unquoted identifiers because many people previously used them. Examples are those in the following list:

  • ACTION
  • BIT
  • DATE
  • ENUM
  • NO
  • TEXT
  • `TIME
  • TIMESTAMP

所以我猜这意味着同行压力将 TIMESTAMP 从保留字列表中删除了。哈!

关于sql - mysql 时间戳语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2754900/

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