You are on page 1of 7

Eng.

Afnan Alkhorasani IT 21/12/2020

DISJOINT

SQL> Create table student


( stdno number primary key ,
stdname varchar2(10) not null ,
std_type char(1) not null check(std_type in ('L','F')) ,
birthdate date ,
constraint student_uq unique (stdno,std_type)
);

Table created.

SQL> create table Local_std


( stdno number ,
std_type char(1) not null check (std_type = 'L') ,
nationality_no number not null ,
constraint local_std_fk foreign key(stdno,std_type) references student
(stdno,std_type)
Eng.Afnan Alkhorasani IT 21/12/2020

);

Table created.

SQL> alter table local_std


add primary key(stdno);

Table altered.

SQL> create table Foreign_std


( stdno number ,
std_type char(1) not null check (std_type = 'F') ,
passport_no number not null ,
Country varchar2(10)
constraint Foreign_std_fk foreign key (stdno,std_type) references student
(stdno,std_type)
);

Table created.

SQL> alter table foreign_std


add primary key(stdno);

Table altered.

SQL> insert into student values (1,'SAMI','L','30-DEC-99');


Eng.Afnan Alkhorasani IT 21/12/2020

1 row created.

SQL> insert into student values (2,'ARWA','L','30-DEC-88');

1 row created.

SQL> insert into student values (3,'ALI','F','30-DEC-99');

1 row created.

SQL> insert into student values (4,'amera','F','30-DEC-99');

1 row created.

SQL> select * From student ;

STDNO STDNAME S BIRTHDATE


---------- ---------- - ---------
1 SAMI L 30-DEC-99
2 ARWA L 30-DEC-88
3 ALI F 30-DEC-99
4 amera F 30-DEC-99

SQL> insert into local_std values(1,'L',345411);

1 row created.
Eng.Afnan Alkhorasani IT 21/12/2020

SQL> insert into local_std values(2,'F',55411);


insert into local_std values(2,'F',55411)
*
ERROR at line 1:
ORA-02290: check constraint (AFNAN.SYS_C005508) violated

SQL> insert into local_std values(2,'L',55411);

1 row created.

SQL> select * from local_std ;

STDNO S NATIONALITY_NO
---------- - --------------
1L 345411
2L 55411

SQL> insert into foreign_std values (3,'F',386342,'OMAN');

1 row created.

SQL> insert into foreign_std values (4,'L',686342,'SYRIA');


insert into foreign_std values (4,'L',686342,'SYRIA')
*
ERROR at line 1:
Eng.Afnan Alkhorasani IT 21/12/2020

ORA-02290: check constraint (AFNAN.SYS_C005513) violated

SQL> insert into foreign_std values (4,'F',686342,'SYRIA');

1 row created.

SQL> COMMIT ;

Commit complete.

SQL> SELECT * fROM FOREIGN_STD ;

STDNO S PASSPORT_NO COUNTRY


---------- - ----------- ----------
3F 386342 OMAN
4F 686342 SYRIA
Eng.Afnan Alkhorasani IT 21/12/2020

OVERLAP

SQL> Create table person


( empno number primary key ,
name varchar2(10) not null ,
birthdate date
);

Table created.

SQL> create table driver


( empno number references person(empno),
License_no number not null ,
Hourly_sal number(5)
);

Table created.
Eng.Afnan Alkhorasani IT 21/12/2020

SQL> alter table driver


add primary key(empno);

Table altered.

SQL> create table employee


( empno number references person(empno),
job varchar2(10) not null ,
constant_sal number(10)
);

Table created.

SQL> alter table employee


add primary key(empno);

Table altered.

You might also like