-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger.sql
More file actions
34 lines (30 loc) · 714 Bytes
/
trigger.sql
File metadata and controls
34 lines (30 loc) · 714 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
25
26
27
28
29
30
31
32
33
34
delimiter $$
create trigger testa_aumento
after update on livros for each row
begin
if(new.preco>1.2*old.preco) then
insert into auditoria(codigo_livro, valor_antigo, valor_novo)
values(new.codLivro, old.preco, new.preco);
end if;
end
$$
create trigger atualiza_qtdLivros_add
after insert on autores_livros for each row
begin
update autores
set qtd_livros=qtd_livros+1
where new.matriculaAutor=matricula;
end
$$
create trigger atualiza_qtdLivros_remove
after delete on autores_livros for each row
begin
update autores
set qtd_livros=qtd_livros-1
where old.matriculaAutor=matricula;
end
$$
delimiter ;
alter table autores
add Qtd_livros int;
drop trigger atualiza_qtdLivros_add;