我正在尝试从 2 列创建主键,但效果不佳

I'm trying to create a primary key from 2 columns, but it doesn't work well

我正在自学Oracle。

这是我的代码:

create table Schedule
(
    Schedule_SN number(10) primary key,
    ScreeningDate date not null,
    Price number(6) not null
);
    
create table Seat 
(
    Schedule_SN number(10) REFERENCES Schedule(Schedule_SN),
    Seat_SN varchar2(4) not null
);
    
create table Reservation
(
    Reservation_SN number(15) primary key,
    DCtype number(2) not null,
    DCamount number(7),
    PaymentMethod number(1) not null,
    TotalPrice number(7) not null,
    ReservationDate date not null
);
    
create table Reservation_details    ** I need help here **
(
    Reservation_SN number(15) REFERENCES Reservation(Reservation_SN),
    Schedule_SN number(10) REFERENCES Schedule(Schedule_SN),
    Seat_SN varchar2(10) REFERENCES Seat(Seat_SN),
    CONSTRAINT Reservation_detailesPK primary key (Reservation_SN, Schedule_SN)
);

错误信息:

Errors - ORA-02270: no matching unique or primary key for this column-list
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement gives a column-list for which there is no matching unique or primary key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS catalog view

如何让我的 2 列 (Reservation_SN, Schedule_SN) 成为主键?

问题出在 seat_sn。您希望 reservation_details 中的子列引用 seat 中的父列,但父列不是主键或唯一键。实际上,seat 没有主键;只需将 seat_sn 作为此 table 的主键(如果这适合您的用例),其余的应该 运行 可以:

create table seat (
    schedule_sn nmber(10) references schedule(schedule_sn),
    seat_sn varchar3(4) primary key
)

Demo on DB Fiddle