I am trying to find a solution for this.
For the database class, I need to implement the following:
Table HUSBANDS: (Name Varchar2(10)) (Wife Varchar2(10))
Table WIVES: (Name Varchar2(10)) (Husband Varchar2(10))
and using Oracle restrictions, with the following exceptions:
- No two husbands having the same name
- No two wives can have the same name.
- Each wife must have one and only one husband
- Every husband should have one and only wife
So far I have implemented a table in Oracle SQL:
create table husbands(
name varchar2(10) not null
, wife varchar2(10) not null
);
create table wives(
name varchar2(10) not null
, husband varchar2(10) not null
);
I am sure that I solved points 1 and 2 using the correct primary keys:
alter table husbands
add constraint husbands_pk
primary key(name);
alter table wives
add constraint wives_pk
primary key(name);
And here I ran into problems. I decided to use foreign keys to implement steps 3 and 4:
alter table husbands
add constraint husbands_fk_wife
foreign key(wife)
references wives(name);
alter table wives
add constraint wives_fk_husband
foreign key(husband)
references husbands(name);
, , - . , , , , . , , . , .
, . , , .