触发器里的都是什么意思啊?
发布网友
发布时间:2022-04-28 11:38
我来回答
共2个回答
热心网友
时间:2023-10-06 06:19
最基本的触发器是针对表的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;
热心网友
时间:2023-10-06 06:20
触发器就是当你做一件事情
在某个时间你还要做另外一件事情
这时你就要用到触发器
就是在一个特定的时间去执行另外一个命令
热心网友
时间:2023-10-06 06:19
最基本的触发器是针对表的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;
热心网友
时间:2023-10-06 06:20
触发器就是当你做一件事情
在某个时间你还要做另外一件事情
这时你就要用到触发器
就是在一个特定的时间去执行另外一个命令