-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaula2450.sql
More file actions
24 lines (22 loc) · 908 Bytes
/
aula2450.sql
File metadata and controls
24 lines (22 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
create or replace trigger baixa_estoque
after insert or update or delete of ven_quantidade on venda
for each row
begin
if inserting then
update estoque set est_quantidade = est_quantidade - :new.ven_quantidade
where est_codigo = :new.ven_codprod;
elsif deleting then
update estoque set est_quantidade = est_quantidade + :old.ven_quantidade
where est_codigo = :old.ven_codprod;
elsif updating then
update estoque set est_quantidade = est_quantidade + :old.ven_quantidade
where est_codigo = :old.ven_codprod;
update estoque set est_quantidade = est_quantidade - :new.ven_quantidade
where est_codigo = :new.ven_codprod;
end if;
end baixa_estoque;
select * from estoque;
select * from venda;
insert into venda (ven_codigo, ven_codprod, ven_quantidade) values(3, 4, 7);
delete venda where ven_codigo = 3;
update venda set ven_quantidade = 5 where ven_codigo = 3;