{"id":6195,"date":"2011-11-20T15:20:19","date_gmt":"2011-11-20T06:20:19","guid":{"rendered":"http:\/\/haakondahl.com\/blog\/?p=2405"},"modified":"2011-11-20T15:20:19","modified_gmt":"2011-11-20T06:20:19","slug":"sql-triggers","status":"publish","type":"post","link":"https:\/\/balldiamondball.com\/blog\/sql-triggers\/","title":{"rendered":"SQL Triggers"},"content":{"rendered":"<p>A fact which seems buried to me is that an <strong>after<\/strong> trigger actually does still have access to both the <strong>inserted<\/strong> and <strong>deleted<\/strong> virtual tables.<\/p>\n<p>So if you have been struggling to re-implement a simple <strong>insert<\/strong>, <strong>update<\/strong>, or <strong>delete<\/strong> because you feel you must use an <strong>instead of<\/strong> trigger in order to access the values in <strong>inserted<\/strong> or <strong>deleted<\/strong>, relax. \u00a0You&#8217;re doing it wrong.<\/p>\n<p>I can beef this up with some code, and I suppose I will, but the code is not the issue&#8211;it&#8217;s the concept, and once I learned to rely on the <strong>inserted<\/strong> and <strong>deleted<\/strong> tables persisting until my trigger itself goes out of scope, my life got much simpler.<\/p>\n<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"https:\/\/balldiamondball.com\/blog\/wp-login.php\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"6195\" data-trigger-type=\"like\" data-restriction=\"user\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\r\n    <a href=\"https:\/\/balldiamondball.com\/blog\/wp-login.php\" class=\"pld-dislike-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"6195\" data-trigger-type=\"dislike\" data-restriction=\"user\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-down\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\r\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>A fact which seems buried to me is that an <strong>after<\/strong> trigger actually does still have access to both the <strong>inserted<\/strong> and <strong>deleted<\/strong> virtual tables.<\/p>\n<p>So if you have been struggling to re-implement a simple <strong>insert<\/strong>, <strong>update<\/strong>, or <strong>delete<\/strong> because you feel you must use an <strong>instead of<\/strong> trigger in order to access the values in <strong>inserted<\/strong> or <strong>deleted<\/strong>, relax. \u00a0You&#8217;re doing it wrong.<\/p>\n<p>I can beef this up with some code, and I suppose I will, but the code is not the issue&#8211;it&#8217;s the concept, and once I learned to rely on the <strong>inserted<\/strong> and <strong>deleted<\/strong> tables persisting until my trigger itself goes out of scope, my life got much simpler.<\/p>\n<p> <a href=\"https:\/\/balldiamondball.com\/blog\/wp-login.php\" class=\"pld-like-trigger pld-like-dislike-trigger \" title=\"\" data-post-id=\"6195\" data-trigger-type=\"like\" data-restriction=\"user\" data-already-liked=\"0\"> <i class=\"fas fa-thumbs-up\"><\/i> <\/a> <a href=\"https:\/\/balldiamondball.com\/blog\/wp-login.php\" ... <a href=\"https:\/\/balldiamondball.com\/blog\/sql-triggers\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":34128,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[232,261],"tags":[],"class_list":["post-6195","post","type-post","status-publish","format-standard","hentry","category-five-by-seven","category-sql"],"_links":{"self":[{"href":"https:\/\/balldiamondball.com\/blog\/wp-json\/wp\/v2\/posts\/6195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/balldiamondball.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/balldiamondball.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/balldiamondball.com\/blog\/wp-json\/wp\/v2\/users\/34128"}],"replies":[{"embeddable":true,"href":"https:\/\/balldiamondball.com\/blog\/wp-json\/wp\/v2\/comments?post=6195"}],"version-history":[{"count":0,"href":"https:\/\/balldiamondball.com\/blog\/wp-json\/wp\/v2\/posts\/6195\/revisions"}],"wp:attachment":[{"href":"https:\/\/balldiamondball.com\/blog\/wp-json\/wp\/v2\/media?parent=6195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/balldiamondball.com\/blog\/wp-json\/wp\/v2\/categories?post=6195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/balldiamondball.com\/blog\/wp-json\/wp\/v2\/tags?post=6195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}