MYSQL - 无法创建表

时间:2009-11-24 06:16:34

标签: mysql mysql-error-1064

我正在使用MYSQL 5.1。当我要创建一个表时,它会抛出这样的错误,

查询:

CREATE TABLE IF NOT EXISTS payment_status (
  STATUS_ID int(3) unsigned NOT NULL DEFAULT '0' ,
  STATUS_NAME varchar(50) NOT NULL DEFAULT '' ,
  DESC varchar(100) ,
  PRIMARY KEY (STATUS_ID),
  UNIQUE KEY XPKPAYMENT_STATUS (STATUS_ID)
)

错误:

Error Code : 1064
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 varchar(100) ,
  PRIMARY KEY (STATUS_ID),
  UNIQUE KEY XPKPAYMENT_STATUS (S' at line 4
(0 ms taken)

2 个答案:

答案 0 :(得分:3)

DESC是一个保留的MYSQL字(曾经使用ORDER BY Column1 DESC ???)。

将单词括在反引号(`)中,查询运行正常:

CREATE TABLE IF NOT EXISTS payment_status (
  STATUS_ID int(3) unsigned NOT NULL DEFAULT '0' ,
  STATUS_NAME varchar(50) NOT NULL DEFAULT '' ,
  `DESC` varchar(100) ,
  /* note the backticks on the above line */
  PRIMARY KEY (STATUS_ID),
  UNIQUE KEY XPKPAYMENT_STATUS (STATUS_ID)
)

虽然我建议重命名该列以避免进一步的麻烦。

答案 1 :(得分:3)

DESC是一个保留字,用反引号包裹起来..

`DESC`