diff --git a/cst363/lab/triggers-lab.pdf b/cst363/lab/triggers-lab.pdf new file mode 100644 index 0000000..73d319d Binary files /dev/null and b/cst363/lab/triggers-lab.pdf differ diff --git a/cst363/lec/lec10.md b/cst363/lec/lec10.md new file mode 100644 index 0000000..c20d480 --- /dev/null +++ b/cst363/lec/lec10.md @@ -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'; +``` +