找不到MySQL语法错误

时间:2013-02-16 02:32:53

标签: mysql

USE waterloo;

DROP TABLE IF EXISTS waterloo;
CREATE TABLE waterloo
(
id              int unsigned NOT NULL auto_increment,   # Unique ID for the record
building        varchar(255) NOT NULL,                  # Name of building
floor           int unsigned NOT NULL,                  # Floor of building
gender          varchar(255) NOT NULL,                  # Gender of bathroom
location        int unsigned NOT NULL,                  # Convenience of location of     bathroom
cleanliness     int unsigned NOT NULL,                  # Cleanliness of bathroom
stalls          int unsigned NOT NULL,                  # Number of stalls
noise           int unsigned NOT NULL,                  # Ambient noise
lines           int unsigned NOT NULL,                  # Length of lines at peak hours
graffiti        int unsigned NOT NULL,                  # Amount of graffiti on the walls
PRIMARY KEY     (id)
);

我收到以下错误:

  

错误1064(42000):您的SQL语法有错误;检查   手册,对应右边的MySQL服务器版本   在'lines int unsigned NOT NULL,graffiti int附近使用的语法   第11行的无符号NOT NULL)

2 个答案:

答案 0 :(得分:2)

LINES是MySQL中的保留字。但是,您仍然可以将其用作列名。只需将它包装在背景中

`lines`

答案 1 :(得分:0)

行是MySQL中的保留字 - 在它周围添加刻度并且它应该可以工作。

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

CREATE TABLE waterloo
(
id              int unsigned NOT NULL auto_increment,   # Unique ID for the record
building        varchar(255) NOT NULL,                  # Name of building
floor           int unsigned NOT NULL,                  # Floor of building
gender          varchar(255) NOT NULL,                  # Gender of bathroom
location        int unsigned NOT NULL,                  # Convenience of location of     bathroom
cleanliness     int unsigned NOT NULL,                  # Cleanliness of bathroom
stalls          int unsigned NOT NULL,                  # Number of stalls
noise           int unsigned NOT NULL,                  # Ambient noise
`lines`           int unsigned NOT NULL,                  # Length of lines at peak hours
graffiti        int unsigned NOT NULL,                  # Amount of graffiti on the walls
PRIMARY KEY     (id)
);

希望有所帮助。