[英]Creating Table How to key in more than one primary key
My question is how to make this work basically an office and non office workers can have more than one loan but since our loan id primary key I can't more than one any ideas how to do this? 我的问题是如何使这项工作基本上成为办公室,而非办公室工作人员可以拥有多于一笔的贷款,但是由于我们的贷款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;
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.