adding lec10 for db

This commit is contained in:
Medium Fries 2018-10-01 16:46:02 -07:00
parent 1449858ca3
commit e6df867def
2 changed files with 43 additions and 0 deletions

BIN
cst363/lab/triggers-lab.pdf Normal file

Binary file not shown.

43
cst363/lec/lec10.md Normal file
View File

@ -0,0 +1,43 @@
# lec10
This lecture has a corresponding lab excercise who's instructions can be found in `triggers-lab.pdf`.
## What is a trigger
Something that executes when _some operation_ is performed
## Structure
```
create trigger NAME before some_operation
when(condition)
begin
do_something
end;
```
To explain: First we `create trigger` followed by some trigger name.
Then we have to denote that this trigger should fire whenever some operation happens.
This trigger then executes everything in the `begin...end;` section _before_ the new operation happens.
> `after`
Likewise if we want to fire a trigger _after_ some operation we ccan just replace the before keyword with `after`.
> `new.adsf`
Refers to _new_ value being added to a table.
> `old.adsf`
Refers to _old_ vvalue being changed in a table.
## Trigger Metadata
If you want to look at what triggers exist you can query the `sql_master` table.
```
select * from sql_master where name='trigger';
```