M358 - Using triggers
fellstrider.com - the logo!
Home| OU Study Rooms | M358 Index | Block 1 - Information Systems | Block 2 - Relational Theory | Block 3 - SQL
 
Using triggers

Triggers

A further use of compound statements is in the use of triggers in SQL. A trigger is defined for use with a table (subject table), where the table is updated by a method specified by the compound statement when the trigger is executed. A trigger is is quite likely to be triggered without the user being aware of the fact.

The hidden effect of a trigger is comparable to the referential actions associated with foreign keys.

The trigger below demonstrates the automatic updating of one table triggered by the updating of a different table.

CREATE TRIGGER add_enrolment 
   AFTER INSERT ON mod_enrolment 
   REFERENCING NEW AS new_enrolment 
   FOR EACH ROW
BEGIN
   UPDATE mod_course
   SET student_count = student_count + 1
   WHERE mod_course.course_code = new_enrolment.course_code;
END

What it all means

Triggers can be used in a variety of situations including:

Triggers do not have any privileges associated with them. However, the owner of a trigger that references a subject table not belonging to them, must have the appropriate privileges for that table.

A trigger should be seen as part of the processing of the triggering statement, and all processing must be completed successfully or not at all.

Home| OU Study Rooms | M358 Index | Block 1 - Information Systems | Block 2 - Relational Theory | Block 3 - SQL
Move on to Transaction Management.

Valid CSS! Valid XHTML 1.0!

Comments, suggestions, ideas to
Stuart Banner