首页 > 代码库 > 简单入门的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;
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。