0

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
3
  • It's not good to use timestamp for a field name. Jul 21, 2011 at 7:49
  • According to the error message, you also have a default '' at the end of your station line. Are you sure that's your exact input?
    – user684934
    Jul 21, 2011 at 7:49
  • And since you have station as the Primary Key, you don't need another UNIQUE constraint on it. Jul 21, 2011 at 7:50

3 Answers 3

4

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.

1
  • Actually there was an option for TIMESTAMP length/format. MySQL 5.0.51 creates the table but shows this warning when the OP's code is run: 'TIMESTAMP(14)' is deprecated; use 'TIMESTAMP' instead Jul 21, 2011 at 8:04
3

'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 
0
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.