0

I have an MySQL command:

use hsm_thilisar_cz; CREATE TABLE GODS (
      id INT NOT NULL AUTO _INCREMENT ,
      name TEXT ,
      range BOOL ,
      free BOOL ,
      lore LONGTEXT ,
      PRIMARY KEY ( id )
);

but if I execute it, i would get an error: (translated from Czech because of Czech MySQL server)

#1064-Your syntax is strange near `range BOOL ,free BOOL ,lore LONGTEXT ,
PRIMARY KEY ( id ));` on line 4

Is there any idea, what I have wrong? Thank you for your answers. ^Solved^

But another problem...

CREATE TABLE GUIDE ( 
   id INT NOT NULL AUTO_INCREMENT,
   godId INT NOT NULL,
   userId INT NOT NULL,
   item1 INT,
   item2 INT,
   item3 INT,
   item4 INT,
   item5 INT,
   item6 INT,
   itemA1 INT,
   itemA2 INT,
   itemC1 INT,
   itemC2 INT,
   notes LONGTEXT,
   mode TEXT,
   guideTimeDate TIMESTAMP,
   PRIMARY KEY(id);

an error on line 18

#1064-Your syntax is strange near '' on line 18.

How can I solve this issue, when MySQL doesn't tell me, where is my syntax incorrect... Thank for your time, that you spent on solving this problem.

4

2 回答 2

2

RANGE是保留关键字,恰好是您的列的名称。为了避免语法错误,应使用反引号对列名进行转义。前任,

use hsm_thilisar_cz; 
CREATE TABLE GODS 
(
      id INT NOT NULL AUTO _INCREMENT ,
      name TEXT ,
      `range` BOOL ,          -- wrap with backticks
      free BOOL ,
      lore LONGTEXT ,
      PRIMARY KEY ( id )
);

我宁愿更改不在保留关键字列表中的列名,以防止将来再次出现相同的错误。

use hsm_thilisar_cz; 
CREATE TABLE GODS 
(
      id INT NOT NULL AUTO _INCREMENT ,
      name TEXT ,
      gods_range BOOL ,         
      free BOOL ,
      lore LONGTEXT ,
      PRIMARY KEY ( id )
);
于 2013-04-24T07:29:26.657 回答
0

“范围”是一个 MySql 关键字。你不能使用它。我试过了,它奏效了:

CREATE TABLE GODS (
      id INT NOT NULL AUTO_INCREMENT ,
      name TEXT ,
      myrange BOOL ,
      free BOOL ,
      lore LONGTEXT ,
      PRIMARY KEY ( id )
);
于 2013-04-24T07:31:45.003 回答