无法在mysql中创建表-错误1064 [英] Table cannot be created in mysql -Error 1064

查看:747
本文介绍了无法在mysql中创建表-错误1064的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用查询在MySQL中创建表

I am trying to create a table in MySQL with the query

CREATE TABLE ofRosterGroups (
  rosterID              BIGINT          NOT NULL,
  rank                  TINYINT         NOT NULL,
  groupName             VARCHAR(255)    NOT NULL,
  PRIMARY KEY (rosterID, rank),
  INDEX ofRosterGroup_rosterid_idx (rosterID)
);

但是每次我也进行更新时,它似乎都抛出错误.我不知道这是怎么回事.

but seems like it is throwing error everytime I made updates too. I don't know what is going wrong with it.

出现错误是

您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以使用正确的语法 在'rank TINYINT NOT NULL附近,groupName
第3行的VARCHAR

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 'rank TINYINT NOT NULL, groupName
VARCHAR at line 3

推荐答案

MySQL 8.0.2添加了对窗口rank函数的支持,使其成为

MySQL 8.0.2 added support for the window rank function, making it a reserverd word.

您可以使用反引号(`)将其转义:

You could escape it using backticks (`):

CREATE TABLE ofRosterGroups (
  rosterID              BIGINT          NOT NULL,
  `rank`                TINYINT         NOT NULL, -- Here
  groupName             VARCHAR(255)    NOT NULL,
  PRIMARY KEY (rosterID, `rank`), -- And here
  INDEX ofRosterGroup_rosterid_idx (rosterID)
);

但是最好使用不是保留字的名称,例如rosterRank而不是rank:

But it may be a better idea to just use a name that isn't a reserved word, such as rosterRank instead of rank:

CREATE TABLE ofRosterGroups (
  rosterID              BIGINT          NOT NULL,
  rosterRank            TINYINT         NOT NULL, -- Here
  groupName             VARCHAR(255)    NOT NULL,
  PRIMARY KEY (rosterID, rosterRank), -- And here
  INDEX ofRosterGroup_rosterid_idx (rosterID)
);

这篇关于无法在mysql中创建表-错误1064的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆