告诉我mysql 8中的正确语法

s4n0splo  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(311)
CREATE TABLE socialgroupcategory (
 socialgroupcategoryid INT unsigned NOT NULL auto_increment,
 creatoruserid INT unsigned NOT NULL,
 title VARCHAR(250) NOT NULL,
 description TEXT NOT NULL,
 displayorder INT unsigned NOT NULL,
 lastupdate INT unsigned NOT NULL,
 groups INT unsigned DEFAULT '0',
 PRIMARY KEY  (socialgroupcategoryid),
 KEY displayorder (displayorder)
);

mysql错误:sql语法错误;请查看与您的mysql服务器版本对应的手册,以了解在第8行的“groups int unsigned default”“0”、主键(socialgroupcategoryid)、键dis”附近使用的正确语法错误号:1064
MySQL5.7-好的
mysql 8-错误

polhcujo

polhcujo1#

GROUPS 已添加为mysql 8中的保留关键字。根据官方文件:
组(r);8.0.2增加(保留)
您应该使用backticks来使用保留关键字命名列/表。请使用以下(请注意背面打勾) groups ):

CREATE TABLE socialgroupcategory (
 socialgroupcategoryid INT unsigned NOT NULL auto_increment,
 creatoruserid INT unsigned NOT NULL,
 title VARCHAR(250) NOT NULL,
 description TEXT NOT NULL,
 displayorder INT unsigned NOT NULL,
 lastupdate INT unsigned NOT NULL,
 `groups` INT unsigned DEFAULT '0',
 PRIMARY KEY  (socialgroupcategoryid),
 KEY displayorder (displayorder)
);

相关问题