sql - mysql 时间戳语法错误

标签 sql mysql

我有这段 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/

相关文章:

php - postgresql/php 中的 SQL 语法错误

sql - 一起使用 INSERT 和 WITH 语句时出错

php - 搜索结果直接进入搜索结果页面

php - 使用 PHP 插入 MySQL 数据库时出现土耳其字符问题

php - 如何省略某些字段中包含零的记录?

sql - Postgresql,函数通过调用另一个函数返回查询

c# - 迭代多个 foreach 循环时出现的问题

.net - 检索所有子项及其子项,递归 SQL

javascript - 使用 php + mysql 填充 morris.js

mysql - 如何从 mysql 查询中排除不常用的用户名?