Triggers

Triggers are an efficient way of using SQL commands to interact efficiently with the database. They are quick, and are embedded within the create trigger command.

A trigger is made up of a trigger name, references to the tables involved, an event of time (like before, or after value changes), the type of operation (like insert, update, or delete), with a variety of tables and columns to complete the operation.

The syntax has to be right and the tests should ensure that the updates and changes are correct to ensure data concurrency and stability with no corruptions.

This trigger is called update_customer_trigger, which performs an UPDATE query on the customers table. The update is going to affect the tel_no column. So, the current telephone column tel_no is going to be updated, where it will equal the value from the new table, and its column tel_no—(tel_no = new.tel_no), where the link of customer name (customer_name), equals the old.name column.

Updated triggers must use specific columns for a table, which are predefined, unlike the insert or delete ones

sqlite> select sql from sqlite_master where name='update_customer_trigger';

CREATE TRIGGER update_customer_trigger UPDATE OF tel_no ON customers    BEGIN     UPDATE orders SET tel_no = new.tel_no WHERE customer_name = old.name;   END