语法错误使用名为“desc”的列创建表

时间:2023-01-19 18:32:51

I can never seem to be able to create MySQL tables with columns of the type TEXT. Here's my MySQL:

我似乎永远无法使用TEXT类型的列创建MySQL表。这是我的MySQL:

CREATE TABLE factions(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(16) NOT NULL, desc TEXT NOT NULL, admins TEXT NOT NULL, mods TEXT, members TEXT, land TEXT, enemies TEXT, allies TEXT)

When it's run, I get this:

当它运行时,我得到这个:

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 'desc text NOT NULL, admins text NOT NULL, mods text, members text, land text, en' at line 1

I can't figure out what's wrong! I'm using Java if it makes any difference.

我无法弄清楚出了什么问题!如果它有任何区别,我正在使用Java。

3 个解决方案

#1


15  

desc is a reserved word and shouldn't be used as a name of a column. You can use desc as a name of a column, but if you do, you must always wrap it in back-ticks.

desc是保留字,不应用作列的名称。您可以使用desc作为列的名称,但如果这样做,则必须始终将其包装在后面。

CREATE TABLE factions(
   id INT NOT NULL AUTO_INCREMENT,
   PRIMARY KEY(id), 
   name    VARCHAR(16) NOT NULL, 
   `desc`  TEXT NOT NULL, 
   admins  TEXT NOT NULL, 
   mods    TEXT, 
   members TEXT, 
   land    TEXT, 
   enemies TEXT, 
   allies  TEXT
);

The above is tested and works, but since you'll always have to wrap it in back-ticks (in every INSERT, UPDATE and DELETE) you may want to change the name, or just get in the habit of wrapping all fields in back-ticks, which has other advantages.

上面的测试和工作,但因为你总是必须将它包装在后面的标记中(在每个INSERT,UPDATE和DELETE中)你可能想要更改名称,或者只是养成包装所有字段的习惯-ticks,具有其他优点。

#2


1  

change the column name desc to any something different since it is a reserverd word for descend or describe

将列名desc更改为任何不同的内容,因为它是用于descend或describe的保留字

#3


0  

desc is a reserved word and can't shall not be given as a name to a table or column. You may use description as the column name. With the name change, your statement should work.

desc是保留字,不能作为表或列的名称给出。您可以使用description作为列名。随着名称的更改,您的声明应该有效。

#1


15  

desc is a reserved word and shouldn't be used as a name of a column. You can use desc as a name of a column, but if you do, you must always wrap it in back-ticks.

desc是保留字,不应用作列的名称。您可以使用desc作为列的名称,但如果这样做,则必须始终将其包装在后面。

CREATE TABLE factions(
   id INT NOT NULL AUTO_INCREMENT,
   PRIMARY KEY(id), 
   name    VARCHAR(16) NOT NULL, 
   `desc`  TEXT NOT NULL, 
   admins  TEXT NOT NULL, 
   mods    TEXT, 
   members TEXT, 
   land    TEXT, 
   enemies TEXT, 
   allies  TEXT
);

The above is tested and works, but since you'll always have to wrap it in back-ticks (in every INSERT, UPDATE and DELETE) you may want to change the name, or just get in the habit of wrapping all fields in back-ticks, which has other advantages.

上面的测试和工作,但因为你总是必须将它包装在后面的标记中(在每个INSERT,UPDATE和DELETE中)你可能想要更改名称,或者只是养成包装所有字段的习惯-ticks,具有其他优点。

#2


1  

change the column name desc to any something different since it is a reserverd word for descend or describe

将列名desc更改为任何不同的内容,因为它是用于descend或describe的保留字

#3


0  

desc is a reserved word and can't shall not be given as a name to a table or column. You may use description as the column name. With the name change, your statement should work.

desc是保留字,不能作为表或列的名称给出。您可以使用description作为列名。随着名称的更改,您的声明应该有效。