gpt4 book ai didi

mysql - phpMyAdmin 中的 SQL 保留字语法错误

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:52 25 4
gpt4 key购买 nike

尝试在 phpMyAdmin 中执行以下代码时出现以下错误。我正在使用 WAMP 服务器和 MySQL 版本 5.5.8::

错误是:

#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 'NUMERIC(6)   not null, payee  VARCHAR2(20)   not null, amount     DECIMAL(6,2)   no' at line 3

SQL 是:

CREATE TABLE checks 
(
check NUMERIC(6) not null,
payee VARCHAR2(20) not null,
amount DECIMAL(6,2) not null,
remarks VARCHAR2(20) not null
)

编辑

我也在尝试执行此操作,但它也给出了错误:

CREATE TABLE deposits
(
deposit NUMBER(8),
whopaid VARCHAR(25),
amount DECIMAL(6,2),
remarks VARCHAR(20)
)

最佳答案

你需要用反引号转义 check 因为它是一个 reserved word .在 MySQL 中没有 varchar2 数据类型,只有 varchar

CREATE TABLE checks 
(
`check` NUMERIC(6) not null,
payee VARCHAR(20) not null,
amount DECIMAL(6,2) not null,
remarks VARCHAR(20) not null
)

同时在您的第二个创建语句中将 NUMBER 替换为 NUMERIC

CREATE TABLE deposits
(
deposit NUMERIC(8),
whopaid VARCHAR(25),
amount DECIMAL(6,2),
remarks VARCHAR(20)
)

SQLFiddle example

参见 MySQL String data typesMySQL numeric data types

关于mysql - phpMyAdmin 中的 SQL 保留字语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12631808/

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