{"id":61006,"date":"2018-10-31T11:00:00","date_gmt":"2018-10-31T09:00:00","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=61006"},"modified":"2018-10-29T15:52:10","modified_gmt":"2018-10-29T13:52:10","slug":"mysql-triggers-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/","title":{"rendered":"MySQL Triggers Tutorial"},"content":{"rendered":"<h2 id=\"introduction\">1. Introduction<\/h2>\n<p>In this post, we feature a comprehensive Tutorial on MySQL Triggers and how do they work.\u00a0<a href=\"https:\/\/www.mysql.com\/\" target=\"_blank\" rel=\"noopener\">MySQL<\/a>\u00a0is one of the most used SQL databases in many of the world-enterprise applications due to its ability to manage transactions and the ACID-behaviour which is built into its core. One of the reasons MySQL is so popular is due to the easiness it provides for its usage and its related commands. In the open source web application framework LAMP (which consist of Linux, Apache, MySQL and PHP),\u00a0MySQL server is a central &amp; important component. The MySQL Database server is written using C and C++ which internally uses\u00a0a lexical analyser to parse and understand the SQL queries.<\/p>\n<p>For this lesson, we need to have a complete MySQL Server installation so that we can run examples for the Triggers we create. Please go through\u00a0the <a href=\"https:\/\/examples.javacodegeeks.com\/enterprise-java\/sql-enterprise-java\/mysql-server-tutorial\/\" target=\"_blank\" rel=\"noopener\">MySQL Server Tutorial<\/a> lesson to understand how installation can be done with some simple commands to get started with MySQL Triggers.<\/p>\n<h2 id=\"introduction\">2. What are MySQL Triggers?<\/h2>\n<p>MySQL Triggers are simple programs (written in SQL itself) which are executed automatically when something happens. This event can be a simple insertion, update or a delete operation in a Table. Whenever there is an event on a Table for which a Trigger is defined, the program is executed by the MySQL server to do something else as well. This can be any operation which related to keeping the database state consistent or populating a table with a set of events which happened in the update of the table.<\/p>\n<p>MySQL Triggers are a powerful tool which is used at a great extent in maintaining a consistent state of a database and make sure that changes in records of a single table are reflected at all the places needed in the database. Although MySQL triggers sound to be very powerful (they are) but they are also associated with some important\u00a0<strong>limitations<\/strong> which limit their use. The most important limitation with MySQL Triggers is debugging. If you use a MySQL Trigger in an application manage DB consistency, it is difficult to debug any issues because there is no way to apply breakpoints and check the program step by step. Neither logging can be applied to a trigger program. To sum up, let&#8217;s cover some great\u00a0<strong>advantages<\/strong> for MySQL Triggers:<\/p>\n<ol>\n<li>They provide a great way to check and implement data integrity<\/li>\n<li>Avoid errors in business logic by implementing solutions at the database layer<\/li>\n<li>They are a great alternative to schedules tasks which can be easily ill-performant. Triggers are triggered at the right moment, after each update operation or as we desire<\/li>\n<li>Auditing of the database changes is easy to implement with Triggers<\/li>\n<\/ol>\n<p>Now, it is time to describe the\u00a0<strong>disadvantages<\/strong> to use Triggers in an application:<\/p>\n<ol>\n<li>If we want to make sure that database integrity and consistency is maintained, Triggers can become quite long and coupled with application logic and still can&#8217;t replace all validations which are needed at an application level.<\/li>\n<li>Triggers work completely behind the scene. For this reason, it is not possible to figure out everything which happens at the database layer.<\/li>\n<li>If there are too many triggers at the database level, they can block database transactions which are originated from application level until a trigger is complete.<\/li>\n<li>It is possible that we want to trigger an operation only when an event happens 10 times or 100 times. This is not possible with SQL Triggers as they are stateless in themselves.<\/li>\n<\/ol>\n<h2 id=\"introduction\">3. Getting Started with MySQL Triggers<\/h2>\n<p>In MySQL, a Trigger is a very simple tool which consists of SQL statements which are executed when an event occurs. Any table can be associated with a Trigger along with an event. This Trigger can be invoked when the coupled events occur. In MySQL, there is six type of events which are defined here. Also, there are size triggers only, which can be bounded to events in a table. These are:<\/p>\n<ol>\n<li>BEFORE INSERT is triggered before data is inserted into the associated table.<\/li>\n<li>AFTER INSERT is triggered after data is inserted into the associated table.<\/li>\n<li>BEFORE UPDATE is triggered before data in the\u00a0associated table is updated.<\/li>\n<li>AFTER UPDATE is triggered after data in the associated table is updated.<\/li>\n<li>BEFORE DELETE is triggered before data is removed from the\u00a0associated table.<\/li>\n<li>AFTER DELETE is triggered after data is removed from the\u00a0associated table.<\/li>\n<\/ol>\n<p><figure id=\"attachment_61060\" aria-describedby=\"caption-attachment-61060\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger.png\"><img decoding=\"async\" class=\"wp-image-61060 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger.png\" alt=\"MySQL Triggers\" width=\"820\" height=\"631\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger.png 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-300x231.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-768x591.png 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-61060\" class=\"wp-caption-text\">MySQL Triggers<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Before MySQL v5.7.2, it was not possible to define multiple trigger events for the same trigger event but now it has been made possible. Note that a trigger is\u00a0<strong>only triggered with\u00a0INSERT, DELETE or UPDATE statements only<\/strong> and not for any other statement like TRUNCATE etc. But again, there are statements which use\u00a0INSERT statement behind the scenes such as REPLACE statement or LOAD DATA statement. If we use these statements, the corresponding triggers associated with the table will be triggered.<\/p>\n<h2 id=\"introduction\">4. Storing MySQL Triggers<\/h2>\n<p>MySQL Triggers are stored in the directory <code>\/data\/classicmodels<\/code> with the name\u00a0<code>tablename.TRG<\/code> and <code>triggername.TRN<\/code> :<\/p>\n<ol>\n<li>The <code>tablename.TRG<\/code> file associates the trigger to the corresponding table<\/li>\n<li>The <code>triggername.TRN<\/code> file contains the trigger definition which will be executed once an event occurs<\/li>\n<\/ol>\n<p>We can back up the MySQL triggers by copying the trigger files to the backup folder or at any other place we wish to. We can also treat the trigger folder as a VCS repository and take its backup whenever something changes.<\/p>\n<h2 id=\"introduction\">5. Creating MySQL Triggers<\/h2>\n<p>Now that we have some great knowledge related to MySQL triggers and where are they stored, we can start creating a Trigger. Let us look at the basic syntax of a Trigger here:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Trigger Syntax<\/em><\/span><\/p>\n<pre class=\"brush:bash\">CREATE TRIGGER trigger_name trigger_time trigger_event\r\n ON table_name\r\n FOR EACH ROW\r\n BEGIN\r\n ...\r\n END;\r\n<\/pre>\n<p>Let us look at some points for the syntax we defined above:<\/p>\n<ul>\n<li><code>CREATE TRIGGER<\/code> statement marks the beginning of a Trigger definition. It is good if the Trigger name follows a specific naming convention <code>[trigger time]_[table name]_[trigger event]<\/code> like <code>after_author_added<\/code>.<\/li>\n<li>A Trigger can be invoked <code>AFTER<\/code> or <code>BEFORE<\/code> an event occurs which must be defined after a name is provided for the Trigger.<\/li>\n<li><code>trigger_event<\/code> can be <code>INSERT<\/code>, <code>UPDATE<\/code> or <code>DELETE<\/code>. Once one of this happens, a Trigger is invoked.<\/li>\n<li>On the second line, we provide the table name with which this Trigger will be associated. This is mandatory to be done as a Trigger without a Table cannot exist in MySQL.<\/li>\n<li>An SQL Trigger starts with a <code>BEGIN<\/code> statement and end with an <code>END<\/code> statement. Between these statements, we define the logic for the Trigger.<\/li>\n<\/ul>\n<p>Let us start creating an example Trigger. To do this, we first look at the databases we have in our system:<\/p>\n<p><figure id=\"attachment_59997\" aria-describedby=\"caption-attachment-59997\" style=\"width: 554px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/09\/show-databases.png\"><img decoding=\"async\" class=\"size-full wp-image-59997\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/09\/show-databases.png\" alt=\"MySQL Triggers - Display databases\" width=\"554\" height=\"369\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/09\/show-databases.png 554w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/09\/show-databases-300x200.png 300w\" sizes=\"(max-width: 554px) 100vw, 554px\" \/><\/a><figcaption id=\"caption-attachment-59997\" class=\"wp-caption-text\">MySQL Triggers &#8211; Display databases<\/figcaption><\/figure><\/p>\n<p>We will make use of <code>jcg_schema<\/code> schema. Let us look at the tables we have in that schema:<\/p>\n<p><figure id=\"attachment_60839\" aria-describedby=\"caption-attachment-60839\" style=\"width: 546px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-table-list.png\"><img decoding=\"async\" class=\"size-full wp-image-60839\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-table-list.png\" alt=\"MySQL Triggers: Display Tables\" width=\"546\" height=\"312\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-table-list.png 546w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-table-list-300x171.png 300w\" sizes=\"(max-width: 546px) 100vw, 546px\" \/><\/a><figcaption id=\"caption-attachment-60839\" class=\"wp-caption-text\">MySQL Triggers: Display Tables<\/figcaption><\/figure><\/p>\n<p>Now, we will create a new table to keep an audit of Authors being added to the system and also when any information about them is edited or they are completely removed from the system. Here is the create table statement for the <code>author_audit<\/code> table:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Create Author Audit<\/em><\/span><\/p>\n<pre class=\"brush:bash\">CREATE TABLE author_audit (\r\n    id INT AUTO_INCREMENT PRIMARY KEY,\r\n    authorId INT NOT NULL,\r\n    name VARCHAR(50) NOT NULL,\r\n    changedate DATETIME DEFAULT NULL,\r\n    action VARCHAR(50) DEFAULT NULL\r\n);\r\n<\/pre>\n<p>Now, we create a new Trigger for the Insert event on the AUthor table, like:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Create Insert Trigger<\/em><\/span><\/p>\n<pre class=\"brush:bash\">DELIMITER $$\r\nCREATE TRIGGER after_author_added\r\n    AFTER INSERT ON Author\r\n    FOR EACH ROW\r\nBEGIN\r\n    INSERT INTO author_audit\r\n    SET action = 'insert',\r\n        authorId = NEW.id,\r\n        name = NEW.name,\r\n        changedate = NOW();\r\nEND$$\r\nDELIMITER ;\r\n<\/pre>\n<p>There is an important thing to notice here. We can get properties of the row being affected through the NEW keyword.<\/p>\n<p>Note that a Trigger made for INSERT uses the <code>NEW<\/code> keyword whereas the Trigger made for DELETE uses the <code>OLD<\/code> keyword to access the row being affected. In the UPDATE trigger, <code>OLD<\/code> can be used to access the row before the change was made to the row and <code>NEW<\/code> to access the row after the change was made to the row. Let&#8217;s make this Trigger and look at all the Triggers which exist in the database as of now with the following command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Display all triggers<\/em><\/span><\/p>\n<pre class=\"brush:bash\">SHOW TRIGGERS;\r\n<\/pre>\n<p>Let us look at the output for this example:<\/p>\n<p><figure id=\"attachment_61071\" aria-describedby=\"caption-attachment-61071\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-display.png\"><img decoding=\"async\" class=\"size-full wp-image-61071\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-display.png\" alt=\"MySQL Trigger: Display Triggers\" width=\"820\" height=\"52\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-display.png 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-display-300x19.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-display-768x49.png 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-61071\" class=\"wp-caption-text\">MySQL Trigger: Display Triggers<\/figcaption><\/figure><\/p>\n<p>Here are the columns which are included in the table above:<\/p>\n<ol>\n<li>Name of the Trigger is displayed<\/li>\n<li>Event is specified like UPDATE, INSERT or DELETE<\/li>\n<li>The name of the Table is shown with which the Trigger is associated<\/li>\n<li>Statement which is being executed is stored in one of the column<\/li>\n<li>Timing column can contain only two values, BEFORE or AFTER. It specified when is the trigger invoked.<\/li>\n<li>Created column contains the date time values when this Trigger was created<\/li>\n<li>sql_mode: This describes the SQL mdoe when the Trigger executes<\/li>\n<li>Definer provides the account name which created the trigger<\/li>\n<\/ol>\n<p>To look if our Trigger is working fine, we will now insert an Author into the table and see if contents are updated in the audit table as well, we use the following command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Insert new Author<\/em><\/span><\/p>\n<pre class=\"brush:bash\">INSERT INTO Author (id, name, post_count) VALUES (7, 'Vyom', 27);\r\n<\/pre>\n<p>Now, we can look at the audit table with the following command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Audit table<\/em><\/span><\/p>\n<pre class=\"brush:bash\">SELECT * FROM author_audit;\r\n<\/pre>\n<p>Let us look at the output this command shows:<\/p>\n<p><figure id=\"attachment_61073\" aria-describedby=\"caption-attachment-61073\" style=\"width: 682px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-audit.png\"><img decoding=\"async\" class=\"size-full wp-image-61073\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-audit.png\" alt=\"MySQL Trigger: Display Audit table\" width=\"682\" height=\"255\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-audit.png 682w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/mysql-trigger-audit-300x112.png 300w\" sizes=\"(max-width: 682px) 100vw, 682px\" \/><\/a><figcaption id=\"caption-attachment-61073\" class=\"wp-caption-text\">MySQL Trigger: Display Audit table<\/figcaption><\/figure><\/p>\n<p>We see that the insertion was done in the audit table as soon as we inserted a new author into the table. Triggers are really fast when you want to perform table manipulation right before or after an operation is done on the table.<\/p>\n<h2 id=\"introduction\">6. Deleting the MySQL Triggers<\/h2>\n<p>In this final section, we can see how we can delete MySQL Triggers with an SQL command as well. To remove an existing Trigger, we can use the following command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Audit table<\/em><\/span><\/p>\n<pre class=\"brush:bash\">DROP TRIGGER table_name.trigger_name;\r\n<\/pre>\n<p>For example, if we want to delete the Trigger which we created in the previous section, we can run the following SQL command:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Audit table<\/em><\/span><\/p>\n<pre class=\"brush:bash\">DROP TRIGGER Author.after_author_added;\r\n<\/pre>\n<p>Please note that if we want to modify a Trigger, we will have to delete it first and recreate it again with the new commands. Unfortunately, there is no command like ALTER command for modifying SQL Triggers.<\/p>\n<h2 id=\"introduction\">7. Conclusion<\/h2>\n<p>In this post, we looked at how we can create triggers for three trigger events in MySQL, including how we can associate them with a table in our database. We also looked at how we can display all the Triggers which exist in our database along with 8 columns in the table which is managed by MySQL itself for administration purposes. One thing to take care when you replicate the database to a new server with only the content from your tables, the Triggers won&#8217;t be backed up if you do not take a complete database back up carefully and your database will start to become inconsistent as soon as data manipulation starts in it.<\/p>\n<p>MySQL Triggers are a very powerful tool with very high performance (usually) but the bad thing is that they can grow very large very easily and quickly once your application starts to grow. The main database consistency should be managed at the application level wherever and whenever possible. Still, MySQL Triggers make a very good companion if you are a database administrator and just want to make things consistent without relying on too much code because after all, the performance of a Trigger is very high because database operations are very fast on the database server itself.<\/p>\n<p>We did not cover all the SQL Trigger sections in this lesson but we did provide a very strong foundation on how Triggers can be created and used to manipulate data in a database. Don\u2019t forget to check the examples of using Java with\u00a0<a href=\"https:\/\/examples.javacodegeeks.com\/enterprise-java\/sql-enterprise-java\/jdbc-best-practices-tutorial\/\" target=\"_blank\" rel=\"noopener\">SQL: JDBC Best Practices Tutorial<\/a>\u00a0and\u00a0<a href=\"https:\/\/examples.javacodegeeks.com\/core-java\/sql\/resultset-sql\/java-jdbc-resultset-example\/\" target=\"_blank\" rel=\"noopener\">Java JDBC ResultSet Example<\/a>. These lessons explain how to effectively use SQL commands with Java &amp;\u00a0<a href=\"https:\/\/examples.javacodegeeks.com\/enterprise-java\/sql-enterprise-java\/jdbc-driver-types-example\/\" target=\"_blank\" rel=\"noopener\">JDBC drivers<\/a>. There are many more examples present on MySQL which can be studied for a deeper understanding of the database.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In this post, we feature a comprehensive Tutorial on MySQL Triggers and how do they work.\u00a0MySQL\u00a0is one of the most used SQL databases in many of the world-enterprise applications due to its ability to manage transactions and the ACID-behaviour which is built into its core. One of the reasons MySQL is so popular &hellip;<\/p>\n","protected":false},"author":154,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[647,1735],"class_list":["post-61006","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-mysql","tag-triggers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MySQL Triggers Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn more about MySQL? Then check out our detailed example on MySQL Triggers!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL Triggers Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about MySQL? Then check out our detailed example on MySQL Triggers!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-31T09:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Shubham Aggarwal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sbmaggarwal\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shubham Aggarwal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/\"},\"author\":{\"name\":\"Shubham Aggarwal\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/da48da5ffe2c95ab19f7b2162a3f30b2\"},\"headline\":\"MySQL Triggers Tutorial\",\"datePublished\":\"2018-10-31T09:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/\"},\"wordCount\":1924,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"mysql\",\"triggers\"],\"articleSection\":[\"sql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/\",\"name\":\"MySQL Triggers Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2018-10-31T09:00:00+00:00\",\"description\":\"Interested to learn more about MySQL? Then check out our detailed example on MySQL Triggers!\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"sql\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"MySQL Triggers Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/da48da5ffe2c95ab19f7b2162a3f30b2\",\"name\":\"Shubham Aggarwal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/09\/Shubham-Aggarwal_avatar_1536328481-96x96.jpeg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/09\/Shubham-Aggarwal_avatar_1536328481-96x96.jpeg\",\"caption\":\"Shubham Aggarwal\"},\"description\":\"Shubham is a Java Backend and Data Analytics Engineer with more than 3 years of experience in building quality products with Spring Boot, MongoDB, Elasticsearch, MySQL, Docker, AWS, Git, PrestoDB tools and I have a deep knowledge and passion towards analytics, Micro-service based architecture, design patterns, antipatterns and software design thinking.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sbmaggarwal\/\",\"https:\/\/x.com\/sbmaggarwal\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/shubham-aggarwal\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MySQL Triggers Tutorial - Java Code Geeks","description":"Interested to learn more about MySQL? Then check out our detailed example on MySQL Triggers!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"MySQL Triggers Tutorial - Java Code Geeks","og_description":"Interested to learn more about MySQL? Then check out our detailed example on MySQL Triggers!","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-10-31T09:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Shubham Aggarwal","twitter_card":"summary_large_image","twitter_creator":"@sbmaggarwal","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Shubham Aggarwal","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/"},"author":{"name":"Shubham Aggarwal","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/da48da5ffe2c95ab19f7b2162a3f30b2"},"headline":"MySQL Triggers Tutorial","datePublished":"2018-10-31T09:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/"},"wordCount":1924,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["mysql","triggers"],"articleSection":["sql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/","name":"MySQL Triggers Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2018-10-31T09:00:00+00:00","description":"Interested to learn more about MySQL? Then check out our detailed example on MySQL Triggers!","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/mysql-triggers-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"sql","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/"},{"@type":"ListItem","position":5,"name":"MySQL Triggers Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/da48da5ffe2c95ab19f7b2162a3f30b2","name":"Shubham Aggarwal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/09\/Shubham-Aggarwal_avatar_1536328481-96x96.jpeg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/09\/Shubham-Aggarwal_avatar_1536328481-96x96.jpeg","caption":"Shubham Aggarwal"},"description":"Shubham is a Java Backend and Data Analytics Engineer with more than 3 years of experience in building quality products with Spring Boot, MongoDB, Elasticsearch, MySQL, Docker, AWS, Git, PrestoDB tools and I have a deep knowledge and passion towards analytics, Micro-service based architecture, design patterns, antipatterns and software design thinking.","sameAs":["https:\/\/www.linkedin.com\/in\/sbmaggarwal\/","https:\/\/x.com\/sbmaggarwal"],"url":"https:\/\/examples.javacodegeeks.com\/author\/shubham-aggarwal\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/61006","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/154"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=61006"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/61006\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=61006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=61006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=61006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}