开发者

can you help me with these sql problem?

hi i am using phpmyadmin 3.3.9 . i have a开发者_开发问答 sql prblem in which i dont know what is the problem at all..

heres the code looks like:

CREATE TABLE metars(
metar varchar( 255 ) NOT NULL default '',
timestamp timestamp( 14 ) NOT NULL ,
station varchar( 4 ) NOT NULL,
PRIMARY KEY ( station ) ,
UNIQUE KEY station( station )
) ENGINE = MYISAM 

and heres the error:

#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 '( 14 ) NOT NULL , station varchar( 4 ) NOT NULL default '', PRIMARY KE' at line 3


Try it with timestamp timestamp NOT NULL ,
There's no length/format option for timestamp (that is: not for mysql 5.1, see ypercube's comment)

see http://dev.mysql.com/doc/refman/5.1/en/create-table.html

data_type:
    BIT[(length)]
  | TINYINT[(length)] [UNSIGNED] [ZEROFILL]
  | SMALLINT[(length)] [UNSIGNED] [ZEROFILL]
  | MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]
  | INT[(length)] [UNSIGNED] [ZEROFILL]
  | INTEGER[(length)] [UNSIGNED] [ZEROFILL]
  | BIGINT[(length)] [UNSIGNED] [ZEROFILL]
  | REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
  | DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]
  | FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL]
  | DECIMAL[(length[,decimals])] [UNSIGNED] [ZEROFILL]
  | NUMERIC[(length[,decimals])] [UNSIGNED] [ZEROFILL]
  | DATE
  | TIME
  | TIMESTAMP
  | DATETIME
  | YEAR
  | CHAR[(length)]
 [...]

But I'd avoid using keywords and/or type names as identifiers.


'timestamp' is a keyword of MySQL. Thus, change the column name 'timestamp' to other or wrap it by grave(`). And you don't have to set the column length of timestamp type.

And PRIMARY KEY also means uniqueness. So, UNIQUE KEY station ( station ) is not necessary here.

CREATE TABLE metars(
metar varchar( 255 ) NOT NULL default '',
`timestamp` timestamp,
station varchar( 4 ) NOT NULL,
PRIMARY KEY ( station )
) ENGINE = MYISAM 


CREATE TABLE metars(
`metar` varchar( 255 ) NOT NULL default '',
`timestamp` timestamp( 14 ) NOT NULL ,
`station` varchar( 4 ) NOT NULL,
PRIMARY KEY ( `station` ) ,
UNIQUE KEY station( `station` )
) ENGINE = MYISAM

this one should be good

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜