2013-02-16 76 views
0
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) 
); 

我得到以下错误:找不到MySQL的语法错误

ERROR 1064 (42000): 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 'lines int unsigned NOT NULL, graffiti int unsigned NOT NULL )' at line 11

+0

也许你忘了添加一个布尔字段“刷新”? – Evgeny 2013-02-16 02:34:10

+0

非常感谢你! – lche 2013-02-16 02:38:50

回答

2

LINES是MySQL中的保留字。不过,您仍然可以将其用作列名称。只是把它放在backtics

`lines` 
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) 
); 

希望有所帮助。