-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adicionando referências e nova aula de triggers
- Loading branch information
1 parent
cdbce25
commit 3eaefb8
Showing
2 changed files
with
56 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Aula Banco de Dados (29/03/2021) | ||
|
||
## Triggers - 44 | ||
|
||
Usa NEW pra indicar o processo ocorrerá no novo registro | ||
Existe também o OLD, pra indicar o registro antigo, normalmente utilizado para fins de comparação na operação de UPDATE | ||
|
||
timing = AFTER, BEFORE | ||
operação = INSERT, UPDATE, DELETE | ||
|
||
### Sintaxe: | ||
```sql | ||
CREATE TRIGGER nome_trigger timing operação | ||
ON nome_tabela | ||
FOR EACH ROW | ||
declarações; | ||
|
||
CREATE TRIGGER tr_desconto BEFORE INSERT | ||
ON produto | ||
FOR EACH ROW | ||
SET NEW.Preco_Desconto = (NEW.Preco_Normal * 0.90); | ||
``` | ||
### Invocando trigger: | ||
```sql | ||
INSERT INTO produto (Nome_produto, Preco_Normal) | ||
VALUES ('Monitor', 1.00); | ||
``` | ||
## Referências: | ||
- https://www.youtube.com/watch?v=JOnkvqUaNOU (MySQL - Triggers - Definição, Sintaxe e Criação - 44) | ||
- https://www.youtube.com/watch?v=YMPGnavrfjs (Criando Trigger no MySQL em poucos minutos) | ||
- https://ayltoninacio.com.br/blog/criando-trigger-no-mysql-em-poucos-minutos |