mySQL 表创建失败 - 错误 1064

发布于 2024-10-24 21:47:19 字数 676 浏览 5 评论 0原文

我正在使用 mysql 管理 GUI 工具来创建表。以下是导致错误的查询语言:

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

我的日期和时间不是 mysql 喜欢的格式,因此我选择 VARCHAR 作为这些列的类型,并将它们称为保留列,直到我可以运行查询来进行必要的转换。

当我尝试通过 GUI 执行此操作时,我得到以下信息:

执行 SQL 命令创建表时出错。
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'NOT NULL,
附近使用的正确语法 `time_holding` VARCHAR NOT NULL,
`open` REAL NOT NULL,
第 3 行的“high”RE(错误 1064)

知道为什么我会收到此消息吗?我已经检查过是否使用了任何保留字,但情况似乎并非如此。

我们将非常感谢您的帮助。

I am using the mysql admin GUI tool to create a table. 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.

When I try to execute this via the GUI I get the following:

Error executing SQL commands to create table.
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 'NOT NULL,
`time_holding` VARCHAR NOT NULL,
`open` REAL NOT NULL,
`high` RE' at line 3 (error 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

z祗昰~ 2024-10-31 21:47:19

您遇到的第一个错误是由于 VARCHAR 字段需要这样的长度:VARCHAR(30)

第二个错误(如果修复 2 个 varchar,则会出现)是最后一个括号之前的逗号。

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;

旁注:您确实知道 MySQL 有特定的类型来处理日期和时间,不是吗?所以你可以:

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

The first error you have is due to that VARCHAR fields need a length like this: VARCHAR(30).

The second error (you'll get if you fix the 2 varchars) is the comma before the last parenthesis.

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? So you could have:

CREATE TABLE `environment`.`moisture` (
  `city_id` INT,
  `date_holding` date,
  `time_holding` time,
  ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文