Intro to Database Systems - Part 14 to 16 : Triggers

A trigger is a procedure that executes automatically as soon as specified changes occur in the DBMS.

A trigger has 3 parts:

Let’s start by creating 4 tables and see how a trigger affects them:

Now let’s define a trigger on table test1:

We notice that we have two parts.

1) An event part: at what type of change should the event happen?

2) An action part: what happens if the trigger runs?

We notice that:

Now let’s populate the databases and see how they look for now, before touching table test1:


Let’s modify table test1 and see how the tables are looking like now:

Here is how the trigger updates the data of the table before the insertion:

1) INSERT INTO test2 SET a2 = NEW.a1;

2) DELETE FROM test3 WHERE a3 = NEW.a1;

3) UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1;


We have 2 types of actions performed:

Some triggers are performed on a WHEN condition, delimiting the new and old data by using the NEW or OLD keyword:


Now read this

A Tiny Intro to the Android Activity Lifecycle

The following is a tutorial on the Android Activity Lifecycle, a concept that occurs pretty often during mobile dev interviews There is also an app to demo the topic, simple, a decent way to go through the cycles and process. It is one... Continue →