简体   繁体   English

mySQL表创建失败 - 错误1064

[英]mySQL table creation fails - error 1064

I am using the mysql admin GUI tool to create a table. 我正在使用mysql管理GUI工具来创建表。 Here is the query language that results in an error: 以下是导致错误的查询语言:

CREATE TABLE `environment`.`moisture` (
  `city_id` INT,
  `date_holding` VARCHAR,
  `time_holding` VARCHAR,
  `open` REAL,
  `high` REAL,
  `low` REAL,
  `close` REAL,
)
CHARACTER SET utf8;

My date and time are not of the format mysql likes so I selected VARCHAR as the type for those columns and referred to them as holding columns until I can run queries to make the necessary conversions. 我的日期和时间不是mysql喜欢的格式,所以我选择VARCHAR作为这些列的类型,并将它们称为保留列,直到我可以运行查询来进行必要的转换。

When I try to execute this via the GUI I get the following: 当我尝试通过GUI执行此操作时,我得到以下内容:

Error executing SQL commands to create table. 执行SQL命令以创建表时出错。
You have an error in your SQL syntax; 您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, 检查与MySQL服务器版本对应的手册,以便在'NOT NULL附近使用正确的语法,
`time_holding` VARCHAR NOT NULL, `time_holding` VARCHAR NOT NULL,
`open` REAL NOT NULL, `open` REAL NOT NULL,
`high` RE' at line 3 (error 1064) 第3行的'high`RE'(错误1064)

Any idea why I am getting this? 知道为什么我得到这个吗? I have checked to see if I am using any reserved words but that does not seem to be the case. 我已经检查过我是否使用了任何保留字,但似乎并非如此。

Your help would be greatly appreciated. 非常感谢您的帮助。

The first error you have is due to that VARCHAR fields need a length like this: VARCHAR(30) . 您遇到的第一个错误是由于VARCHAR字段需要这样的长度: VARCHAR(30)

The second error (you'll get if you fix the 2 varchars) is the comma before the last parenthesis. 第二个错误(如果修复2个varchars,则会得到)是最后一个括号之前的逗号。

CREATE TABLE `environment`.`moisture` (
  `city_id` INT,
  `date_holding` VARCHAR(30),  --or whatever length you want
  `time_holding` VARCHAR(20),  --same
  `open` REAL,
  `high` REAL,
  `low` REAL,
  `close` REAL  --- no comma here
)
CHARACTER SET utf8;

Side note: You do know that MySQL has specific types to handle dates and times, don't you? 旁注:你知道MySQL有特定的类型来处理日期和时间,不是吗? So you could have: 所以你可以:

CREATE TABLE `environment`.`moisture` (
  `city_id` INT,
  `date_holding` date,
  `time_holding` time,
  ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM