你能帮我解决这些sql问题吗?

发布于 2024-11-25 12:18:47 字数 570 浏览 0 评论 0 原文

你好,我正在使用 phpmyadmin 3.3.9 。我有一个 sql 问题,我根本不知道问题是什么..

代码如下:

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 

错误如下:

#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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

戒ㄋ 2024-12-02 12:18:47

尝试使用 timestamp timestamp NOT NULL ,
时间戳没有长度/格式选项(即:不适用于 mysql 5.1,请参阅 ypercube 的评论)

请参阅 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)]
 [...]

但我会避免使用关键字和/或类型名称作为标识符。

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.

赴月观长安 2024-12-02 12:18:47

“timestamp”是 MySQL 的关键字。因此,将列名“timestamp”更改为其他名称或用grave(`) 括起来。并且不必设置时间戳类型的列长度。

而PRIMARY KEY也意味着唯一性。所以,UNIQUE KEY 站(station)在这里是没有必要的。

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

'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 
秋凉 2024-12-02 12:18:47
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

这个应该不错

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文