oracle外键解说

oracle外键解说

以下为在plsql中所试验的语句,可以反映外键的使用方法及作用:

create table job (jid int primary key ,jname varchar2(10));

create table dept (depid int primary key ,depname varchar2(10));

create table emp
(
eid int primary key ,
ename varchar2(10),
jno int constraint fk_jid references job(jid) on delete cascade,
depno int constraint fk_pid references dept(depid)on delete set null)


select * from job
select * from dept
select * from emp

insert into job(jid,jname) values(1,'china')

insert into job(jid,jname) values(3,'japan')

insert into dept(depid,depname) values(2,'b')

insert into dept(depid,depname) values(3,'c')


insert into emp(eid,ename,jno,depno) values(8,'z',1,2)

delete from dept where depid=2

select * from emp

delete from job where jid=1

select * from emp