Triggers in MySQL on Windows

Triggers in MySQL on Windows

Hi. Today, let us have a look at an interesting topic in MySQL, Triggers. For those who don’t know SQL, Structured Query Language (SQL) is a standard computer language for relational database management and data manipulation.

Hi. Today, let us have a look at an interesting topic in MySQL, Triggers.

For those who don’t know SQL, Structured Query Language (SQL) is a standard computer language for relational database management and data manipulation. MySQL is an example of a Database Management System. Pssst… It is pretty famous.

Photo by Caspar Camille Rubin on Unsplash

Triggers help us instantiate an action when a specific cause is detected. In simple words, perform a specific, pre-defined action when a particular change is caused to the table.

Let us look at an example of what a trigger command in MySQL looks like and later we can discuss its functioning.

DELIMITER $$
CREATE
   TRIGGER my_trigger BEFORE INSERT
   ON EMPLOYEE
   FOR EACH ROW BEGIN
      INSERT INTO trigger_test VALUES('add new emp');
END $$
DELIMITER;

Explanation

The above code creates a trigger which inserts a record with the text ‘add new emp’ in ‘trigger_test’ table of the ‘EMPLOYEE’ database before each record is entered by the user. So, for example, if the user entered 2 records, he/she would see the records in the order:

‘add new emp’, ‘record 1’, ‘add new emp’, ‘record 2’

‘my_trigger’ is the name of the trigger we just created.

You could change the syntax to AFTER INSERT to add the ‘add new emp’ record after each row is added to the table by the user which will look like this:

DELIMITER $$
CREATE
   TRIGGER my_trigger AFTER INSERT
   ON EMPLOYEE
   FOR EACH ROW BEGIN
      INSERT INTO trigger_test VALUES('add new emp');
END $$
DELIMITER;

mysql

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Best MySQL DigitalOcean Performance – ScaleGrid vs. DigitalOcean Managed Databases

Compare ScaleGrid MySQL vs. DigitalOcean Managed Databases - See which offers the best MySQL throughput, latency, and pricing on DigitalOcean across workloads.

Exploring MySQL Binlog Server - Ripple

How MySQL Ripple binlog server can help you improve the performance of your master server by introducing a proxy server between the master and slave servers.MySQL does not limit the number of slaves that you can connect to the master server in a replication topology.

MySQL Tutorial - Learn MySQL from Scratch

Complete MySQL Course: Beginner to Advanced. MySQL Tutorial - Learn MySQL from scratch and go from beginner to advanced in MySQL.

MySQL Tutorial: A Beginners Guide To Learn MySQL

MySQL Tutorial: A Beginners Guide To Learn MySQL - Let's take a look at a very in-depth MySQL tutorial that explores all the operations and commands that you need to explore your databases...

How to Install MySQL on Mac & Configure MySQL in Terminal

In this tutorial, we are going to learn how to install MySQL community server on Mac and setting up the MySQL in Terminal app. Mac OS doesn’t come along with the pre-configured version of MySQL, but this step by step guide will make the task easy for you. By the end of this tutorial, you will be able to set up the MySQL server on your Mac system for local development purposes.