我遇到了一个我无法找到解决方案的问题,因为它非常具体,我希望你能帮助我:
CREATE TABLE books (
passagierid NUMBER NOT NULL CONSTRAINT fk_bucht_passagier REFERENCES passagier, --FK
flightnr VARCHAR2(8) NOT NULL,
dep_date DATE NOT NULL,
CONSTRAINT fk_bucht_flug FOREIGN KEY (flightnr, dep_date) REFERENCES flug, --FK
CONSTRAINT pk_bucht PRIMARY KEY (passagierid, flightnr, dep_date), --PK
bookingnr NUMBER NOT NULL CONSTRAINT ak_bookingnr UNIQUE,
[...]
seatnr VARCHAR2(5) NOT NULL,
[...]
-- something like that:
CONSTRAINT chk_sitzpl_gleiche_buchung CHECK((seatnr,bookingnr,dep_date,flightnr)
NOT IN (SELECT seatnr,bookingnr,dep_date,flightnr FROM books))
);
因此,应检查这些输入,其中相同的航班号,日期和座位必须具有相同的预订编号:
-- insert into books values (...,'PW2345','19.11.2013 15:02:00',1,...,'12c',...)
-- insert into books values (...,'PW2345','19.11.2013 15:02:00',2,...,'12c',...) not ok
答案 0 :(得分:1)
您需要的是对这些列的唯一约束。
语法是:
CREATE TABLE XYZ(
....,
....,
CONSTRAINT <constraint_name> UNIQUE(column-list separated by commas));
您可以阅读更多相关信息here