Anda tidak dapat membuat batasan untuk memeriksanya dengan struktur tabel yang ada. Cara umum untuk melakukannya adalah seperti ini:
create table loaner (
loan_id number(5) primary key,
loan_type VARCHAR2 (16),
loan_start_date date,
loan_end_date date,
constraint loaner_uk unique (loan_id, loan_type)
);
create table office_worker (
worker_id number(5) primary_key,
loan_id number(5),
loan_type VARCHAR2 (16),
worker_name varchar2(50),
constraint office_worker_loaner_fk foreeign key (loan_id, loan_type) references loaner (loan_id, loan_type),
constraint office_worker_loan_type_chk check (loan_type = 'OFFICE')
);
create table nonoffice_worker (
nonworker_id number(5) primary_key,
loan_id number(5),
loan_type VARCHAR2 (16),
nonworker_name varchar2(50),
constraint nonoffice_worker_loaner_fk foreeign key (loan_id, loan_type) references loaner (loan_id, loan_type),
constraint nonoffice_worker_loan_type_chk check (loan_type = 'NONOFFICE')
);
Yaitu:
- Buat batasan UNIK yang berlebihan di (load_id, loan_type) di tabel pertama.
- Tambahkan loan_type ke tabel subtipe dan dasarkan kunci asing (loan_id, loan_type).
- Tambahkan batasan pemeriksaan ke setiap tabel subjenis untuk memastikan jenis_pinjaman yang benar digunakan.