{"id":26502,"date":"2023-06-08T07:21:00","date_gmt":"2023-06-08T05:21:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=26502"},"modified":"2023-08-09T15:29:09","modified_gmt":"2023-08-09T13:29:09","slug":"create-sql-server-triggers","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/","title":{"rendered":"Create SQL Server Triggers (code examples)"},"content":{"rendered":"\n<p>How to create and use SQL Server triggers ? MS SQL triggers are powerful database objects that monitor and respond to specific events. In this guide, we&#8217;ll explore what triggers are, why they&#8217;re used, and how to effectively implement them. By the end, you&#8217;ll have a solid understanding of the topic, coupled with hands-on examples.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#1-what-are-sql-server-triggers\" >1. What are SQL Server Triggers?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#2-different-types-of-triggers-in-sql-server\" >2. Different types of triggers in SQL Server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#3-practical-examples-of-sql-server-triggers\" >3. Practical examples of SQL Server triggers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#4-best-practices-for-sql-server-triggers\" >4. Best Practices for SQL Server Triggers<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-1-what-are-sql-server-triggers\"><span class=\"ez-toc-section\" id=\"1-what-are-sql-server-triggers\"><\/span>1. What are SQL Server Triggers?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Triggers in SQL Server are special stored procedures automatically executed or fired when certain events occur. These events could be changes in data due to INSERT, UPDATE, or DELETE operations. Simply put, they &#8220;trigger&#8221; a response when specific conditions are met.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-different-types-of-triggers-in-sql-server\"><span class=\"ez-toc-section\" id=\"2-different-types-of-triggers-in-sql-server\"><\/span>2. Different types of triggers in SQL Server<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>SQL Server supports various types of triggers. Here, we\u2019ll delve into the three main types:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>AFTER Triggers<\/strong>: Fired after the triggering action, e.g., after a data insert or update.<\/li>\n\n\n\n<li><strong>INSTEAD OF Triggers<\/strong>: Fired in place of the triggering action, providing an alternative action.<\/li>\n\n\n\n<li><strong>DDL Triggers<\/strong>: Respond to Data Definition Language (DDL) events, like when a table is created.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-practical-examples-of-sql-server-triggers\"><span class=\"ez-toc-section\" id=\"3-practical-examples-of-sql-server-triggers\"><\/span>3. Practical examples of SQL Server triggers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Now, let&#8217;s roll up our sleeves and jump into some practical examples. The following code snippets will offer you a real-world feel of triggers in action. The main types of triggers are these ones:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>AFTER trigger<\/li>\n\n\n\n<li>INSTEAD OF trigger<\/li>\n\n\n\n<li>DDL trigger<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-1-after-trigger-example\">3.1 AFTER Trigger Example<\/h3>\n\n\n\n<p>Imagine you want to log all changes to a <code>Products<\/code> table. You could create an <code>AFTER<\/code> trigger for this.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE TRIGGER trg_after_insert\nON Products\nAFTER INSERT\nAS\nBEGIN\n   INSERT INTO Products_Log(Date, Action, ProductName)\n   SELECT GETDATE(), 'INSERT', ProductName FROM inserted;\nEND;\n<\/pre>\n\n\n\n<p>This trigger logs every new product added to the <code>Products<\/code> table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-2-instead-of-trigger-example\">3.2 INSTEAD OF Trigger Example<\/h3>\n\n\n\n<p>Suppose you have a view combining two tables, and you want to insert data into both tables when inserting into the view. An <code>INSTEAD OF<\/code> trigger can handle this.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE TRIGGER trg_instead_of_insert\nON ProductView\nINSTEAD OF INSERT\nAS\nBEGIN\n   INSERT INTO Table1(...)\n   SELECT ... FROM inserted;\n\n   INSERT INTO Table2(...)\n   SELECT ... FROM inserted;\nEND;\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-3-ddl-trigger-example\">3.3 DDL Trigger Example<\/h3>\n\n\n\n<p>To prevent any new table creation, use a DDL trigger like this one below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE TRIGGER NoNewTables\nON DATABASE \nFOR CREATE_TABLE\nAS\nBEGIN\n   RAISERROR ('New tables are not allowed.', 16, 1);\n   ROLLBACK;\nEND;\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-4-best-practices-for-sql-server-triggers\"><span class=\"ez-toc-section\" id=\"4-best-practices-for-sql-server-triggers\"><\/span>4. Best Practices for SQL Server Triggers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The best practice presented below is supported by three pillars:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Minimize trigger logic<\/strong>: Triggers should be lightweight to avoid performance bottlenecks.<\/li>\n\n\n\n<li><strong>Avoid recursive triggers<\/strong>: Ensure that a trigger doesn\u2019t fire actions that trigger itself.<\/li>\n\n\n\n<li><strong>Use triggers for essential logic only<\/strong>: Don\u2019t rely heavily on triggers for business logic.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">4.1 Minimize Trigger Logic<\/h3>\n\n\n\n<p>Firstly, triggers play a crucial role in database operations by responding to specific events. However, the key to maximizing their efficiency lies in the simplicity and brevity of their logic. A heavy or complex trigger can consume significant resources, leading to increased execution time and a potential slowdown of the entire system. By keeping triggers lightweight, you ensure that the database performs at its optimal speed, reducing the chances of performance bottlenecks. It&#8217;s always advisable to review the logic embedded within a trigger and eliminate any non-essential components. This way, the trigger can execute its function quickly without causing unnecessary strain on the server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.2 Avoid Recursive Triggers<\/h3>\n\n\n\n<p>Secondly, recursive triggers can be problematic. At its core, a recursive trigger is one that inadvertently or deliberately fires itself, either directly or through a chain of other triggers. This can lead to an endless loop, which, in turn, can consume all available system resources and halt the database&#8217;s operations. Recursive triggers can also complicate debugging processes, making it challenging to pinpoint issues or understand the exact sequence of events that led to a particular outcome. To maintain a healthy database environment, it&#8217;s crucial to design triggers with a clear understanding of the chain of events they initiate. Proper testing and monitoring can help identify and prevent unwanted recursive behavior.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.3 Use Triggers for Essential Logic Only<\/h3>\n\n\n\n<p>Thirdly, while triggers offer a range of functionalities and can be tempting to use for various tasks, it&#8217;s essential to exercise restraint. Relying heavily on triggers for business logic can clutter the project and make its operations opaque and hard to trace. Instead, business logic\u2014being the rules and procedures that dictate how a business operates\u2014should ideally reside in the application layer, not the database layer. This segregation ensures that the database focuses solely on data management while the application handles business processes. By limiting the use of triggers to only essential database-related logic, you ensure clarity, maintainability, and scalability of the system. It&#8217;s a sustainable approach that lends itself to easier troubleshooting and more straightforward system upgrades in the future.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-conclusion-on-t-sql-triggers\">Conclusion on T-SQL triggers<\/h3>\n\n\n\n<p>This tutorial learn how to create and use SQL Server triggers, when applied judiciously, this techniques can be very powerful allies, especially in automation ang logging. They provide automated, consistent responses to changes in your data.<\/p>\n\n\n\n<p>Indeed, by understanding the types of triggers and their appropriate applications, as demonstrated in the examples, you can leverage them to enhance database operations and ensure data integrity. We hope you found this article insightful. For more related topics, check out our <a href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedure\/\"><strong>tutorial on SQL Server Stored Procedures<\/strong><\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"2rpavddjuo\"><a href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedure\/\">How to create a SQL Server stored procedure ?<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;How to create a SQL Server stored procedure ?&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedure\/embed\/#?secret=2FWJL4qD3H#?secret=2rpavddjuo\" data-secret=\"2rpavddjuo\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>How to create and use SQL Server triggers ? MS SQL triggers are powerful database objects that monitor and respond to specific events. In this guide, we&#8217;ll explore what triggers are, why they&#8217;re used, and how to effectively implement <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/\" title=\"Create SQL Server Triggers (code examples)\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":6400,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-26502","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create SQL Server Triggers (code examples) - T-SQL<\/title>\n<meta name=\"description\" content=\"Tutorial on how to create SQL Server triggers and use them, to understand their types, use-cases, and get hands-on with practical examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create SQL Server Triggers (code examples)\" \/>\n<meta property=\"og:description\" content=\"Tutorial on how to create SQL Server triggers and use them, to understand their types, use-cases, and get hands-on with practical examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-08T05:21:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-09T13:29:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2020\/07\/fresh-glass-coffee-cup-2D256C64A99_1920x1080.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"Create SQL Server Triggers (code examples)\",\"datePublished\":\"2023-06-08T05:21:00+00:00\",\"dateModified\":\"2023-08-09T13:29:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/\"},\"wordCount\":805,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2020\/07\/fresh-glass-coffee-cup-2D256C64A99_1920x1080.jpeg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/\",\"name\":\"Create SQL Server Triggers (code examples) - T-SQL\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2020\/07\/fresh-glass-coffee-cup-2D256C64A99_1920x1080.jpeg\",\"datePublished\":\"2023-06-08T05:21:00+00:00\",\"dateModified\":\"2023-08-09T13:29:09+00:00\",\"description\":\"Tutorial on how to create SQL Server triggers and use them, to understand their types, use-cases, and get hands-on with practical examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2020\/07\/fresh-glass-coffee-cup-2D256C64A99_1920x1080.jpeg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2020\/07\/fresh-glass-coffee-cup-2D256C64A99_1920x1080.jpeg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create SQL Server Triggers (code examples)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Create SQL Server Triggers (code examples) - T-SQL","description":"Tutorial on how to create SQL Server triggers and use them, to understand their types, use-cases, and get hands-on with practical examples.","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:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/","og_locale":"en_US","og_type":"article","og_title":"Create SQL Server Triggers (code examples)","og_description":"Tutorial on how to create SQL Server triggers and use them, to understand their types, use-cases, and get hands-on with practical examples.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2023-06-08T05:21:00+00:00","article_modified_time":"2023-08-09T13:29:09+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2020\/07\/fresh-glass-coffee-cup-2D256C64A99_1920x1080.jpeg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"Create SQL Server Triggers (code examples)","datePublished":"2023-06-08T05:21:00+00:00","dateModified":"2023-08-09T13:29:09+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/"},"wordCount":805,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2020\/07\/fresh-glass-coffee-cup-2D256C64A99_1920x1080.jpeg","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/","url":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/","name":"Create SQL Server Triggers (code examples) - T-SQL","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2020\/07\/fresh-glass-coffee-cup-2D256C64A99_1920x1080.jpeg","datePublished":"2023-06-08T05:21:00+00:00","dateModified":"2023-08-09T13:29:09+00:00","description":"Tutorial on how to create SQL Server triggers and use them, to understand their types, use-cases, and get hands-on with practical examples.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2020\/07\/fresh-glass-coffee-cup-2D256C64A99_1920x1080.jpeg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2020\/07\/fresh-glass-coffee-cup-2D256C64A99_1920x1080.jpeg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/create-sql-server-triggers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"Create SQL Server Triggers (code examples)"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/26502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=26502"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/26502\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/6400"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=26502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=26502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=26502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}