考虑以下业务领域:
Airline具有唯一的航空公司 ID ( aid) 并包含零个或多个Planes。Plane有一个唯一的飞机 id ( pid) Airline(但来自不同国家的飞机Airlines可以有重叠ids)。Plane都有一个或多个Seats。Seat有一个唯一的座位 id ( sid) (但Seats不同的座位 idPlanes可能有重叠ids)。这是我解决这个问题的尝试:
CREATE SEQUENCE planes_seq;
CREATE TABLE Airlines (
aid INTEGER PRIMARY KEY DEFAULT nextval('planes_seq')
);
CREATE TABLE Planes (
aid INTEGER REFERENCES Airlines(aid)
, pid INTEGER
, PRIMARY KEY(aid, pid)
);
CREATE TABLE Seats ( …Run Code Online (Sandbox Code Playgroud)