我正在尝试创建一个名为'cartable'的sql表。我目前正在使用phpmyadmin通过MAMP(Mac版WAMP)。
当我点击保存按钮时,会出现此错误:
SQL query:
CREATE TABLE `cardatabase`.`CARTABLE` (
`ID` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`SLOTNUMBER` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`STATUS` ENUM( 1 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`LATITUDE` DECIMAL( 20 ) NOT NULL ,
`LONGITUDE` DECIMAL( 20 ) NOT NULL ,
`LOCATION` VARCHAR( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`DEVICEID` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL
) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
MySQL said: Documentation
#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 '1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `LATITUDE` DECIMAL(20) N' at line 1
双数据类型似乎是一个问题,因为当我将其更改为varchar时,会创建表。还有其他方法吗?在此先感谢,非常感谢任何帮助。
答案 0 :(得分:3)
你的问题在于:
`STATUS` ENUM( 1 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
enum
类型应该是字符串对象,而不是数字对象。
ENUM是一个字符串对象,其值从允许值列表中选择,这些值在表创建时在列规范中显式枚举。
枚举值必须是带引号的字符串文字;它可能不是表达式,即使是计算字符串值的表达式。
答案 1 :(得分:2)
枚举行中有错误,您需要预定义枚举值,如下所示:
STATUS
ENUM('ravi','kotwani')CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
完整查询:
CREATE TABLE cardatabase
。CARTABLE
(
ID
VARCHAR(10)CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
SLOTNUMBER
VARCHAR(10)CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
STATUS
ENUM('ravi','kotwani')CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
LATITUDE
DECIMAL(20)NOT NULL,
LONGITUDE
DECIMAL(20)NOT NULL,
LOCATION
VARCHAR(40)CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
DEVICEID
VARCHAR(20)CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL
)ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;