views:

40

answers:

2

I am using MYSQL 5.1. When i am going create a table, it throws error like this,

Query:

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:

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)
+3  A: 

DESC is a reserved MYSQL word (ever used ORDER BY Column1 DESC???).

Enclose the word in backticks (`) and query will run fine:

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)
)

Though I recommend renaming the column to avoid further trouble.

Salman A
+3  A: 

DESC is a reserved word, wrap it around with backticks..

`DESC`
meder
Yes this is the error, After i renamed this word as description, it works fine.Thanks..
Srinivasan