How to Make a Trigger in MySQL Database

Trigger is a stored procedure in Microsoft SQL Server that is automatically executed when the data in the table changes due to the execution of SQL commands (INSERT, UPDATE or DELETE).

Some things that can be done with the Trigger is:
  • Updating other tables when there are changes (insert, update or delete) in the current table.
  • To implement a system log. Any changes, will automatically save to the log table.
  • To perform validation and verification of data before the data is stored.
Here is how to create a database trigger:

  •  Name is the trigger name follows the naming rules of variables in MySQL
  • [BEFORE | AFTER] to determine when the process is automatically executed (before or after the process).
  • [INSERT | UPDATE | DELETE] to determine which process is used as the trigger (trigger) to execute the commands in the triggers.
  • Tablename is the name of the table where the trigger is located.
  • Statement is a set of commands or queries that will be automatically executed if the process defined previously active.
  • First, prepare a database and tables.

    Then create a trigger like this :


    On the trigger, when there is a change in the ITProgrammer table, the table will automatically be affected ITProgrammer2 (also change). or any other way that you can more easily use the JOIN syntax as in the article "Update Table With Data From Another Table In SQL".
    Previous
    Next Post »