0

我是 SQL 新手,在 Navicat for Oracle 中出现此错误。

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

创建 Watched 表时出现错误。我想这与情节表中的多个外键有关,但我似乎无法弄清楚。

4

1 回答 1

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 列。

于 2013-11-04T20:43:24.420 回答