怎样创建触发器?
触发器:在学生表中每录入一个学生信息,就显示“欢迎新同学”。存储过程:名称:“ProcedureQuery”功能:输入学号,输出相应的学生姓名,课程名称,教师姓名。...
触发器:在学生表中每录入一个学生信息,就显示“欢迎新同学”。
存储过程:
名称: “Procedure Query”
功能: 输入学号,输出相应的学生姓名,课程名称,教师姓名。 展开
存储过程:
名称: “Procedure Query”
功能: 输入学号,输出相应的学生姓名,课程名称,教师姓名。 展开
1个回答
展开全部
最基本的触发器是针对表的Insert、Update、Delete这三种操作来的。触发器可以建立在表上,也可以建立在视图上。建立在表上的触发器会在表内容发生改变时触发。建立在视图上的触发器会在视图内容改变时触发。注意,视图触发器仅会在明确对视图进行操作的SQL语句执行时才会触发,当基本表的内容发生改变而引起视图内容变化时,不会触发视图触发器。
下面是建立表触发器的代码:
create or replace trigger tg_E_CONTACT
before update or insert or delete on E_CONTACT
for each row
begin
if inserting then
insert into E_CONTACT@gaac.world
values
(:new.TELEPHONE, :new.EMPLOYEEID, :new.STATUS);
else
if updating then
update E_CONTACT@gaac.world s
set s.TELEPHONE = :new.TELEPHONE,
s.EMPLOYEEID = :new.EMPLOYEEID,
s.STATUS = :new.STATUS
where s.employeeid = :old.employeeid;
else
if deleting then
delete from E_CONTACT@gaac.world s
where s.employeeid = :old.employeeid;
end if;
end if;
end if;
end;
下面是建立视图触发器的代码:(注意里面的instead of)
create or replace trigger tg_E_CONTACT
before instead of update or instead of insert or instead of delete on E_CONTACT
for each row
begin
if inserting then
insert into E_CONTACT@gaac.world
values
(:new.TELEPHONE, :new.EMPLOYEEID, :new.STATUS);
else
if updating then
update E_CONTACT@gaac.world s
set s.TELEPHONE = :new.TELEPHONE,
s.EMPLOYEEID = :new.EMPLOYEEID,
s.STATUS = :new.STATUS
where s.employeeid = :old.employeeid;
else
if deleting then
delete from E_CONTACT@gaac.world s
where s.employeeid = :old.employeeid;
end if;
end if;
end if;
end;
下面是建立表触发器的代码:
create or replace trigger tg_E_CONTACT
before update or insert or delete on E_CONTACT
for each row
begin
if inserting then
insert into E_CONTACT@gaac.world
values
(:new.TELEPHONE, :new.EMPLOYEEID, :new.STATUS);
else
if updating then
update E_CONTACT@gaac.world s
set s.TELEPHONE = :new.TELEPHONE,
s.EMPLOYEEID = :new.EMPLOYEEID,
s.STATUS = :new.STATUS
where s.employeeid = :old.employeeid;
else
if deleting then
delete from E_CONTACT@gaac.world s
where s.employeeid = :old.employeeid;
end if;
end if;
end if;
end;
下面是建立视图触发器的代码:(注意里面的instead of)
create or replace trigger tg_E_CONTACT
before instead of update or instead of insert or instead of delete on E_CONTACT
for each row
begin
if inserting then
insert into E_CONTACT@gaac.world
values
(:new.TELEPHONE, :new.EMPLOYEEID, :new.STATUS);
else
if updating then
update E_CONTACT@gaac.world s
set s.TELEPHONE = :new.TELEPHONE,
s.EMPLOYEEID = :new.EMPLOYEEID,
s.STATUS = :new.STATUS
where s.employeeid = :old.employeeid;
else
if deleting then
delete from E_CONTACT@gaac.world s
where s.employeeid = :old.employeeid;
end if;
end if;
end if;
end;
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询