2013-11-04 130 views
0

我是SQL新手,在Navicat for Oracle中出現此錯誤。SQL:ORA-00904:無效標識符

ORA-00904::創建所述觀看錶時無效的標識符

DROP TABLE Series CASCADE CONSTRAINTS; 
DROP TABLE User1 CASCADE CONSTRAINTS; 
DROP TABLE Following CASCADE CONSTRAINTS; 
DROP TABLE Episode CASCADE CONSTRAINTS; 
--DROP TABLE BUNGALOW CASCADE CONSTRAINTS; 
--DROP TABLE Watched CASCADE CONSTRAINTS; 



CREATE TABLE Series 
( SeriesID NUMBER(5) primary key, 
    Name VARCHAR2(100) NOT NULL, 
    Status VARCHAR2(15), 
    Genre VARCHAR2(100), 
    Country VARCHAR2(100), 
    Network VARCHAR2(100), 
    Runtime VARCHAR2(25) 
); 

CREATE TABLE User1(
    UserID NUMBER(5) primary key, 
    Username VARCHAR2(100) NOT NULL, 
    Country1 varchar2(100), 
    Gender VARCHAR2(10) NOT NULL, 
    Birthday VARCHAR2(100), 
    Timezone VARCHAR2(100), 
    About_me VARCHAR2(300), 
    Password VARCHAR2(100) NOT NULL 
); 

CREATE TABLE Following (
    UserID NUMBER(5) NOT NULL, 
    SeriesID NUMBER(5) NOT NULL, 
    Ignore1 CHAR(1) NOT NULL, 
    constraint Following_pk primary key(UserID, SeriesID), 
    constraint Following_fk1 foreign key(UserID) REFERENCES User1(UserID), 
    constraint Following_fk2 foreign key(SeriesID) REFERENCES Series(SeriesID) 
); 

CREATE TABLE Episode(
    SeriesID NUMBER(5) NOT NULL, 
    Season NUMBER(2) NOT NULL, 
    Episode NUMBER(2) NOT NULL, 
    Name varchar2(100) NOT NULL, 
    Airdate DATE, 
    Summary varchar2(500), 
    constraint episode_pk primary key(SeriesID, Season, Episode), 
    constraint episode_fk foreign key(SeriesID) REFERENCES Series(SeriesID) 
); 

CREATE TABLE Watched(
    UserID NUMBER(5) NOT NULL, 
    SeriesID NUMBER(5) NOT NULL, 
    Season NUMBER(2) NOT NULL, 
    Episode NUMBER(2) NOT NULL, 
    constraint watched_pk primary key(UserID, SeriesID, Season, Episode), 
    constraint watched_fk1 foreign key(UserID) REFERENCES User1(UserID), 
    constraint watched_fk2 foreign key(SeriesID) REFERENCES Episode(SeriesID), 
    constraint watched_fk3 foreign key(Season) REFERENCES Episode(Season), 
    constraint watched_fk4 foreign key(Episode) REFERENCES Episode(Episode), 
); 

的錯誤出現。我想這與Episode-table中的多個外鍵有關,但我似乎無法弄清楚。

回答

0

你有一個逗號多,在最後的約束定義,試試這個:

CREATE TABLE Watched(
    UserID NUMBER(5) NOT NULL, 
    SeriesID NUMBER(5) NOT NULL, 
    Season NUMBER(2) NOT NULL, 
    Episode NUMBER(2) NOT NULL, 
    constraint watched_pk primary key(UserID, SeriesID, Season, Episode), 
    constraint watched_fk1 foreign key(UserID) REFERENCES User1(UserID), 
    constraint watched_fk4 foreign key(Episode, season, seriesid) REFERENCES Episode(SeriesID, Season, Episode) 
); 

而且,你有太多的外鍵 - 而不是3個外鍵引用EPISODE表,你應該只有一個3列。