我的问题是如何使这项工作基本上是一个办公室,非办公室工作人员可以有多个贷款,但由于我们的贷款ID主键我不能超过一个任何想法如何做到这一点?
CREATE TABLE loaner
(
l_id NUMBER(10) primary key,
type VARCHAR2(20),
no_days_overdue NUMBER(3),
loan_start_date date,
loan_end_date date,
fine_imposed NUMBER(55),
constraint loaner_uk unique (l_id, type),
constraint chk_type check (type='office' or type='nonoffice')
);
commit;
CREATE TABLE office
(
office_id NUMBER(5) primary key,
l_id NUMBER(10) ,
type VARCHAR2(10),
office_forname VARCHAR2(30),
office_surname VARCHAR2(30),
email VARCHAR2(50),
address VARCHAR2 (100),
constraint office_fk foreign key (l_id, type) references loaner (l_id, type),
constraint office_type_chk check (type='OFFICE')
);
commit;
CREATE TABLE nonoffice
(
nonoffice_id NUMBER(5),
l_id NUMBER(5),
type VARCHAR2(10),
non_forname VARCHAR2(30),
non_surname VARCHAR2(30),
constraint nonoffice_loaner_fk foreign key (l_id, type) references loaner (l_id, type),
constraint nonoffice_type_chk check (brw_type='nonoffice')
);
commit;
答案 0 :(得分:0)
CREATE TABLE loaner
(
l_id NUMBER(10) primary key,
type VARCHAR2(20),
no_days_overdue NUMBER(3),
loan_start_date date,
loan_end_date date,
fine_imposed NUMBER(55),
office_id NUMBER(5),
nonoffice_id NUMBER(5),
constraint office_fk foreign key (office_id) references office(office_id),
constraint nonoffice_fk foreign key (nonoffice_id) references nonoffice(nonoffice_id)
);
commit;
CREATE TABLE office
(
office_id NUMBER(5) primary key,
l_id NUMBER(10) ,
type VARCHAR2(10),
office_forname VARCHAR2(30),
office_surname VARCHAR2(30),
email VARCHAR2(50),
address VARCHAR2 (100),
);
commit;
CREATE TABLE nonoffice
(
nonoffice_id NUMBER(5) primary key,
l_id NUMBER(5),
type VARCHAR2(10),
non_forname VARCHAR2(30),
non_surname VARCHAR2(30),
);
commit;