首页 > 代码库 > 简单入门的Oracle触发器使用

简单入门的Oracle触发器使用

--建表语句
create table student(id number(9),name varchar2(64),age number(5));create table class(id number(9),name varchar2(64),teacherid number(9),studentid number(9));create table teacher(id number(9),name varchar2(64),age number(5)); --学生信息insert into student values(1,yangml,23);insert into student values(2,zhangj,23);insert into student values(3,zhulj,26);insert into student values(4,chenglp,26);--老师信息insert into teacher values(1,yangls,33);insert into teacher values(2,zhangls,33);insert into teacher values(3,zhuls,33);insert into teacher values(4,chenls,33);--班级信息insert into class values(1,一年级,1,1);insert into class values(2,二年级,2,2);insert into class values(3,三年级,3,3);insert into class values(4,四年级,4,4);--删除触发器create or replace trigger trigdel before delete on class for each rowdeclare -- local variables herebegin delete from teacher where teacher.id=:old.id; delete from student where student.id=:old.id;end trigdel;--测试删除delete from class;select * from class;select * from student;select * from teacher;