2015-11-08 78 views
-1

有人能告訴我爲什麼我得到這個錯誤嗎?謝謝!SQL缺少右括號ORA-00907

CREATE TABLE Booking (
    hotelNo char(2) NOT NULL, 
    guestNo char(2) NOT NULL, 
    dateFrom date  NOT NULL, 
    dateTo date  
    roomNo char(2) NOT NULL, 
    CONSTRAINT booking_pk PRIMARY KEY (hotelNo, guestNo, dateFrom), 
    CONSTRAINT booking_hotel_fk FOREIGN KEY (hotelNo) REFERENCES 
    CONSTRAINT booking_guest_fk FOREIGN KEY (guestNo) REFERENCES Guest(guestNo), 
    CONSTRAINT booking_room_fk FOREIGN KEY (hotelNo, roomNo) 
    REFERENCES Room(hotelNo, roomNo) 
); 

回答

2

您至少有兩個錯誤。在date之後缺少逗號。但是你也沒有完成外鍵引用。所以,這樣的事情:

CREATE TABLE Booking (
    hotelNo char(2) NOT NULL, 
    guestNo char(2) NOT NULL, 
    dateFrom date  NOT NULL, 
    dateTo date, 
    -----------^ 
    roomNo char(2) NOT NULL, 
    CONSTRAINT booking_pk PRIMARY KEY (hotelNo, guestNo, dateFrom), 
    CONSTRAINT booking_hotel_fk FOREIGN KEY (hotelNo) REFERENCES hotel(hotelNo), 
    -------------------------------------------------------------^ 
    CONSTRAINT booking_guest_fk FOREIGN KEY (guestNo) REFERENCES Guest(guestNo), 
    CONSTRAINT booking_room_fk FOREIGN KEY (hotelNo, roomNo) REFERENCES Room(hotelNo, roomNo) 
); 
+0

我錯過了'酒店(hotelNo)':P –

+0

謝謝您的答覆。我會盡快嘗試,SQLFiddle現在剛剛下線:-( – Starbucks

+0

它工作,謝謝。 – Starbucks