求一个简单的SQL触发器
发布网友
发布时间:2022-05-07 01:09
我来回答
共2个回答
热心网友
时间:2022-05-07 02:38
CREATE TRIGGER DELUser ON UserInfo--创建一个DELETE触发器
FOR DELETE--定义出发条件
AS
declare @id int
select @id = userid from deleted--临时表deleted,在每次执行删除后生成,获取到被操纵USERID
print '删除成功'
DELETE USERBed WHERE USERBed.USERID = @id--删除相关联的userbed表中对应的数据
热心网友
时间:2022-05-07 03:56
create or replace trigger trg_rdrecords
before insert on rdrecords
for each row
declare
cnt number(1);
begin
select 1
into cnt
from rdrecord a
where a.id = :new.id
and a.cvouchtype = 1
and rownum <= 1;
if cnt = 1 then
update inventory b set b.cdefine11 = :new.iunitcost where b.cinvcode=:new.cinvcode;
end if;
end;