csnotes/cst363/lec/lec10.md
2018-10-03 13:19:05 -07:00

975 B

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';