SQL 创建数据库的语法错误 table

error in SQL syntax creating a database table

我正在尝试在 mysql 14.14 Distrib 5.6.24 的数据库中创建一个 table,

我想要一个有两列的 table:

SQL:

CREATE TABLE mytable(
    tag MEDIUMTEXT,
    index BIGINT(20)
) 
ENGINE MyISAM;

但是我得到了错误

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 'BIGINT(20)

indexreserved word in MySQL (and any other relational database I can think of). It's used to create, well, indexes.

在 MySQL 中,您可以通过用 ` 字符括起对象名称来转义它们:

CREATE TABLE mytable (
    tag MEDIUMTEXT, 
    `index` BIGINT(20) 
) ENGINE MyISAM;

但通常认为完全避免此类情况是更好的做法。例如,您可以调用数字列 tag_index:

CREATE TABLE mytable (
    tag MEDIUMTEXT, 
    tag_index BIGINT(20) 
) ENGINE MyISAM;