映画を予約できるクライアントのケースです。ただし、一度に所有できるフィルムは最大 10 本までです。これを機能させるには、どのようなチェック制約が必要ですか?
データベースを作成するコードは次のとおりです。
CREATE TABLE ジャンル (PK_GenreID AUTOINCREMENT(13, 1) NOT NULL, GenreNaam TEXT(20),
PRIMARY KEY (PK_GenreID));
CREATE UNIQUE INDEX Index_BC00E533_C727_4D6E ON Genre(GenreNaam);
CREATE TABLE Klant (PK_Klantnummer AUTOINCREMENT(19, 1) NOT NULL, Naam TEXT(20) NOT NULL, Woonplaats TEXT(20), Postcode TEXT(6), Huisnummer TEXT(6), Telefoon TEXT(10), Email TEXT(255) )、
CONSTRAINT PrimaryKey PRIMARY KEY (PK_Klantnummer));
Klant(Naam) で UNIQUE INDEX Index_6827B6DC_E76F_4B57 を作成します。
CREATE TABLE Reserveringen (PK_ReserveringID AUTOINCREMENT(13, 1) NOT NULL, FK_Klantnummer INTEGER, Reserveringsdatum DATE, PRIMARY KEY (PK_ReserveringID),
CONSTRAINT KlantReserveringen FOREIGN KEY (FK_Klantnummer) REFERENCES Klant(PK_Klantnummer) ON UPDATE CASCADE ON DELETE CASCADE);
CREATE TABLE Films (PK_FilmnaamID AUTOINCREMENT(51, 1) NOT NULL, FK_GenreID INTEGER, Filmnaam TEXT(30) WITH COMPRESSION, Releasedatum DATE, Regisseur TEXT(30), CONSTRAINT PrimaryKey PRIMARY KEY (PK_FilmnaamID),
CONSTRAINT GenreFilms FOREIGN KEY (FK_GenreID) REFERENCES Genre(PK_GenreID) ON UPDATE CASCADE ON DELETE CASCADE);
CREATE INDEX PK_FilmnaamID ON Films(PK_FilmnaamID);
CREATE TABLE Beelddrager (PK_FilmID AUTOINCREMENT(50, 1) NOT NULL, FK_FilmnaamID INTEGER, Soort TEXT(50), PRIMARY KEY (PK_FilmID),
CONSTRAINT FilmsBeelddrager FOREIGN KEY (FK_FilmnaamID) REFERENCES Films(PK_FilmnaamID) ON UPDATE CASCADE ON DELETE CASCADE);
CREATE TABLE Beschadiging (PK_BeschadigingID AUTOINCREMENT(14, 1) NOT NULL, FK_FilmID INTEGER, Schade TEXT(255), Datum DATE, CONSTRAINT PrimaryKey PRIMARY KEY (PK_BeschadigingID),
CONSTRAINT BeelddragerBeschadiging FOREIGN KEY (FK_FilmID) REFERENCES Beelddrager(PK_FilmID) ON UPDATE CASCADE ON DELETE CASCADE);
CREATE INDEX PK_BeschadigingID ON Beschadiging(PK_BeschadigingID);
CREATE TABLE Reserveringsregel (FK_ReserveringID INTEGER, FK_FilmID INTEGER, Begindatum DATE, Einddatum DATE, CONSTRAINT BeelddragerReserveringsregel FOREIGN KEY (FK_FilmID) REFERENCES Beelddrager(PK_FilmID) ON UPDATE CASCADE ON DELETE CASCADE, CONSTRAINT ReserveringenReserveringsregel FOREIGN KEY (FK_ReserveringID)カスケード削除時);