-1
所以我試圖創建一個數據庫使用MYSQL,它似乎並沒有添加到終端上的mysql表,以下錯誤代碼顯示:錯誤1064(42000):在第10行附近'''使用正確的語法
**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 ')' at line 10
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 ')' at line 9
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 '(2),
PRIMARY KEY (guest_id),
FOREIGN KEY (res_nr)
)' at line 10
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
mysql> SHOW TABLES;
+---------------------------------+
| Tables_in_xxxxxx_coursework_1 |
+---------------------------------+
| Reservations |
| Room |
+---------------------------------+
2 rows in set (0.00 sec)**
但是,此代碼工作較早,因爲當我輸入「SHOW TABLES;」時它顯示前兩個表房間和預訂所以故障不能在前兩個表中。
CREATE TABLE Room (
id INT AUTO_INCREMENT,
room_id INT (3),
room_type VARCHAR (15),
guest_id INT (8),
res_nr INT (6),
price DECIMAL (6,2) unsigned,
extras_id INT (2),
PRIMARY KEY (id)
);
CREATE TABLE Reservations (
id INT AUTO_INCREMENT,
res_no INT (6),
guest_id INT (8),
hotel_branch INT (5),
room_genre VARCHAR (12),
extras_id INT (2),
room_id int (3),
PRIMARY KEY (id),
FOREIGN KEY (room_id)
REFERENCES Room (id)
);
CREATE TABLE Employees (
id INT AUTO_INCREMENT,
employee_id INT (6),
ni_id INT (9),
first_name VARCHAR (25),
surname VARCHAR (25),
address VARCHAR (100),
PRIMARY KEY (id),
FOREIGN KEY (first_name)
);
CREATE TABLE Hotel (
id INT AUTO_INCREMENT,
hotel_branch INT (5),
employee_id INT (6),
hotel_name CHAR (20),
town VARCHAR(20),
num_rooms INT (3),
PRIMARY KEY (id),
);
CREATE TABLE Guest (
id INT AUTO_INCREMENT,
guest_id INT (8),
res_nr INT(6),
first_name CHAR (25),
surname CHAR (25),
phone_no INT(12),
email VARCHAR (25),
room_id INT(3),
extras_id(2),
PRIMARY KEY (guest_id)
FOREIGN KEY (res_nr)
);
CREATE TABLE Bill (
id INT AUTO_INCREMENT,
invoice_id INT (9),
guest_id INT (8),
room_charge DECIMAL (8,2) unsigned,
extra_charge DECIMAL (6,2) unsigned,
PRIMARY KEY (invoice_id),
FOREIGN KEY (guest_id)
REFERENCES Guest (id)
);