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

次のエラーが表示されます。

エラー 1064 (42000): SQL 構文にエラーがあります。11 行目の「lines int unsigned NOT NULL, graffiti int unsigned NOT NULL )」の近くで使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。

4

2 に答える 2

2

LINESは MySQL の予約語です。ただし、列名として引き続き使用できます。バックティックでラップするだけです

`lines`
于 2013-02-16T02:35:36.700 に答える
0

Lines は 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)
);

それが役立つことを願っています。

于 2013-02-16T02:35:33.247 に答える