{"id":574,"date":"2018-07-02T19:57:04","date_gmt":"2018-07-02T19:57:04","guid":{"rendered":"http:\/\/dbtut.com\/?p=574"},"modified":"2021-02-05T22:38:27","modified_gmt":"2021-02-05T22:38:27","slug":"sql-server-trigger-types","status":"publish","type":"post","link":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/","title":{"rendered":"SQL Server Trigger Types"},"content":{"rendered":"<p>Trigger is used to trigger another event when an event occurs in the database server.<\/p>\n<p>There are 3 types of trigger.<\/p>\n<h3>1) DML(Data Manipulation Language) Trigger<\/h3>\n<h3>2) DDL(Data Definition Language) Trigger<\/h3>\n<h3>3) Logon Trigger<\/h3>\n<h2>DML(Data Manipulation Language) Trigger:<\/h2>\n<p>Includes INSERT, UPDATE, and DELETE operations on the database.<\/p>\n<p>You can also do things using DML Trigger with PRIMARY KEY, FOREIGN KEY, UNIQUE constraint or CHECK CONSTRAINTS.<\/p>\n<p>You can find information about these concepts in my articles titled &#8220;<a href=\"http:\/\/dbtut.com\/index.php\/2018\/06\/14\/what-is-primary-key-and-foreign-key\/\" target=\"_blank\" rel=\"noopener\">What is Primary Key and Foreign Key<\/a>&#8220;, &#8220;<a href=\"http:\/\/dbtut.com\/index.php\/2018\/06\/16\/differences-between-primary-key-and-unique-constraint\/\" target=\"_blank\" rel=\"noopener\">Differences Between Primary Key and Unique Constraint<\/a>&#8221; and &#8220;<a href=\"http:\/\/dbtut.com\/index.php\/2018\/07\/05\/how-to-create-check-constraint\/\" target=\"_blank\" rel=\"noopener\">How To Create\u00a0CHECK CONSTRAINT<\/a>&#8220;.<\/p>\n<p>You can use the DML Triggers when the CONSTRAINTs mentioned above do not meet the functional requirements.<\/p>\n<p><span lang=\"en-US\">DML triggers have tables with the names inserted and deleted to be used in the following examples. <\/span><\/p>\n<p><span lang=\"en-US\">For example, when an insert operation comes in, you can find the records inserted in the inserted table, and when an update or delete operation occurs, you can find the records <\/span><span lang=\"tr\">deleted <\/span><span lang=\"en-US\">in the <\/span><span lang=\"tr\">deleted <\/span><span lang=\"en-US\">table<\/span><\/p>\n<p>There are 2 types of DML Trigger.<\/p>\n<h3>1) AFTER or FOR:<\/h3>\n<p>It is triggered after the completion of any DML operation (INSERT, UPDATE, and DELETE) on the database.<\/p>\n<p>In previous versions of SQL Server it was passed as FOR, so FOR support still continues.<\/p>\n<p>AFTER and FOR mean the same. Let&#8217;s make some examples for AFTER INSERT, AFTER UPDATE and AFTER DELETE.<\/p>\n<p>For each example we will use the table below with the create script.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TABLE [dbo].[TriggerOrnegi](\r\n[ID] [int] NULL,\r\n[AdSoyad] [varchar](100) NULL\r\n) ON [PRIMARY]<\/pre>\n<h3><\/h3>\n<h3>AFTER INSERT:<\/h3>\n<p>Let&#8217;s write the AFTER INSERT Trigger which transfers the insert operations made to the above TriggerOrganization table to another table.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TABLE [dbo].[TriggerOrnegiBackup](\r\n[ID] [int] NULL,\r\n[AdSoyad] [varchar](100) NULL\r\n) ON [PRIMARY]<\/pre>\n<p>Create the trigger with the help of the below script.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TRIGGER Trg_After_Insert\r\nON [dbo].[TriggerOrnegi]\r\nAFTER INSERT AS\r\nBEGIN\r\nINSERT INTO [dbo].[TriggerOrnegiBackup]\r\nSELECT * FROM INSERTED\r\nEND<\/pre>\n<p lang=\"en-US\">Now let&#8217;s do an insert with the following script on our table named TriggerOrnegi.<\/p>\n<p lang=\"en-US\">Next, we&#8217;ll check whether our trigger is working by select on the TriggerOrNegi and TriggerOrnegiBackup tables.<\/p>\n<pre class=\"lang:default decode:true\">INSERT INTO [dbo].[TriggerOrnegi]([ID],[AdSoyad])VALUES(1,'Nurullah \u00c7AKIR')\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegi]\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegiBackup]<\/pre>\n<p>As you can see from the following screenshot, the trigger worked successfully.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png\" alt=\"\" width=\"625\" height=\"371\" \/><\/p>\n<h3><\/h3>\n<h3>AFTER UPDATE:<\/h3>\n<p>When there is an update on the table named &#8220;TriggerOrnegi&#8221;, we use the after update trigger for the reflection of this update on the table named TriggerOrnegiBackup.<\/p>\n<p>The following trigger updates the table named &#8220;TriggerOrnegiBackup&#8221; in the AdSoyad column when an update operation is performed on the AdSoyad column of the table named &#8220;TriggerOrnegi&#8221;.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TRIGGER Trg_After_Update\r\nON [dbo].[TriggerOrnegi]\r\nAFTER UPDATE AS\r\nBEGIN\r\nUPDATE [dbo].[TriggerOrnegiBackup]\r\nSET\u00a0\u00a0\u00a0 [dbo].[TriggerOrnegiBackup].AdSoyad = inserted.AdSoyad\r\nFROM\u00a0\u00a0 [dbo].[TriggerOrnegiBackup]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JOIN inserted\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ON [dbo].[TriggerOrnegiBackup].ID = inserted.ID\u00a0\r\nEND<\/pre>\n<p>To check that the trigger works correctly, run the following query that updates the AdSoyad column in the &#8220;TriggerOrnegi&#8221; table and then selects both tables.<\/p>\n<pre class=\"lang:default decode:true\">UPDATE [dbo].[TriggerOrnegi]\u00a0\u00a0 SET [AdSoyad] = 'Nurullah \u00c7AKIR Kim?' WHERE AdSoyad='Nurullah \u00c7AKIR'\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegi]\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegiBackup]<\/pre>\n<p>As you can see, the trigger worked correctly.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/409.png\" width=\"584\" height=\"254\" \/><\/p>\n<h3>AFTER DELETE:<\/h3>\n<p>Similarly, when there is a deletion in the first table, you should perform the same deletion in the second table.<\/p>\n<p>Create the AFTER DELETE trigger as follows.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TRIGGER Trg_After_Delete\r\nON [dbo].[TriggerOrnegi]\r\nAFTER DELETE AS\r\nBEGIN\r\nDELETE FROM [dbo].[TriggerOrnegiBackup] \r\nWHERE [dbo].[TriggerOrnegiBackup].ID IN (SELECT ID FROM DELETED)\r\nEND<\/pre>\n<p>Let&#8217;s check whether the trigger works by deleting a record from the &#8220;TriggerOrnegi&#8221; table with the help of the following script.<\/p>\n<pre class=\"lang:default decode:true\">DELETE FROM [dbo].[TriggerOrnegi]\u00a0 WHERE [AdSoyad] = 'Nurullah \u00c7AKIR Kim?'\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegi]\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegiBackup]<\/pre>\n<p>As you can see, when we delete a record from the TriggerOrnegi table, the corresponding record is also deleted from the TriggerOrnegiBackup table.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/972.png\" width=\"541\" height=\"330\" \/><\/p>\n<h3><\/h3>\n<h3>2) INSTEAD OF:<\/h3>\n<p>In the AFTER trigger, the trigger was running after the DML operations were successful.<\/p>\n<p>In the INSTEAD OF trigger, this trigger is triggered before the DML operation takes place.<\/p>\n<p>You can use this trigger for many purposes. we will make examples that adopt a single purpose in this article.<\/p>\n<p>Let&#8217;s look at how the INSTEAD OF INSERT, INSTEAD OF UPDATE, and INSTEAD OF DELETE trigger types work.<\/p>\n<h3><\/h3>\n<h3>INSTEAD OF INSERT:<\/h3>\n<p>With INSTEAD OF INSERT, we can say that instead of this insert, insert the following operation before the first insert occurs.<\/p>\n<p>When an insert occurs in the &#8220;TriggerOrNegi&#8221; table, we also insert the same records to the TriggerOrnegiBackup table by incrementing the ID value by 1.<\/p>\n<p>We create the trigger with the following script.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TRIGGER Trg_InsteadOf_Insert ON [dbo].[TriggerOrnegi]\r\nINSTEAD OF INSERT\r\nAS BEGIN\r\nINSERT INTO [dbo].[TriggerOrnegi]([ID],[AdSoyad])Select ID+1,AdSoyad FROM inserted\r\nINSERT INTO [dbo].[TriggerOrnegiBackup]([ID],[AdSoyad])Select ID+1,AdSoyad FROM inserted\r\nEND<\/pre>\n<p>Let&#8217;s do the insert operation into the table named TriggerOrder with the following script.<\/p>\n<p>Then you can see the result by select on two tables. (Before performing this operation, remember to delete all the triggers and records we created in the AFTER example.)<\/p>\n<pre class=\"lang:default decode:true\">INSERT INTO [dbo].[TriggerOrnegi]([ID],[AdSoyad])VALUES(1,'Nurullah \u00c7AKIR')\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegi]\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegiBackup]<\/pre>\n<p lang=\"en-US\">As you can see, even though the ID has a value of 1 in the script, we increased the value by 2 and made the insert operation in both tables.<\/p>\n<p lang=\"en-US\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/841.png\" width=\"601\" height=\"383\" \/><\/p>\n<h3 lang=\"en-US\"><\/h3>\n<h3 lang=\"en-US\">INSTEAD OF UPDATE:<\/h3>\n<p>When the Update statement is run, it executes the statements that will work instead of update. To implement our example, first create a log table with the following script.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TABLE [dbo].[TriggerLog](\r\n[IDMevcutHali] [int] NULL,\r\n[IDUpdateEdilmekIstenenHali] [int] null,\r\n[Aciklama] [varchar](500) NULL\r\n) ON [PRIMARY]<\/pre>\n<p>Trigger will rollback the update if the ID column is updated in our table named &#8220;TriggerOrnegi&#8221; and in the TriggerLog table we created above, we will be entering the ID value that is being tried to change and its description.<\/p>\n<p>Even if the &#8220;AdSoyad&#8221; column is updated, it will apply this update and insert it into the TriggerLog table along with an explanation of which record was updated. You will create the trigger as follows.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TRIGGER Trg_InsteadOf_Update\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ON [dbo].[TriggerOrnegi]\r\n\r\nINSTEAD OF UPDATE\r\nAS\r\nBEGIN\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DECLARE @ID INT, @AdSoyad VARCHAR(100)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SELECT @ID= INSERTED.ID,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @AdSoyad = INSERTED.AdSoyad\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FROM INSERTED\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 IF UPDATE(ID)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BEGIN\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 RAISERROR('ID De\u011feri Update Edilemez.', 16 ,1)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ROLLBACK\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 INSERT INTO [dbo].[TriggerLog]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 VALUES(@ID, 'ID de\u011feri update edilemez.')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 END\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ELSE\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BEGIN\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 UPDATE [dbo].[TriggerOrnegi]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SET AdSoyad = @AdSoyad\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WHERE ID = @ID\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 INSERT INTO [dbo].[TriggerLog]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 VALUES(@ID, 'AdSoyad kolonu update edildi.')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 END\r\nEND<\/pre>\n<p>Now, in our first script, we try to update the ID column in the TriggerOrNegi table, and check if the trigger is working by select on the TriggerOrnegi and TriggerLog tables. Remember to delete the previous triggers.<\/p>\n<pre class=\"lang:default decode:true\">UPDATE [dbo].[TriggerOrnegi] SET ID = 3 Where ID=2\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegi]\r\nGO\r\nSelect * FROM [dbo].[TriggerLog]<\/pre>\n<p>When we run the above script, we get a message stating that the ID value can not be updated and rollback of the update is performed as below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/409-1.png\" width=\"600\" height=\"371\" \/><\/p>\n<p>When we move to the Result tab on the left side of the Messages section on the left, we can see in the TriggerLog table that the record is not updated and what value is requested to be updated.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/765.png\" width=\"517\" height=\"439\" \/><\/p>\n<p>Now let&#8217;s try to update AdSoyad column with the following script.<\/p>\n<pre class=\"lang:default decode:true\">UPDATE [dbo].[TriggerOrnegi] SET AdSoyad = 'Nurullah \u00c7AKIR Kim?' Where ID=2\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegi]\r\nGO\r\nSelect * FROM [dbo].[TriggerLog]<\/pre>\n<p>As you see below, the update operation is performed and then the corresponding Log recording is saved in the TriggerLog table.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/410.png\" width=\"603\" height=\"405\" \/><\/p>\n<h3>INSTEAD OF DELETE:<\/h3>\n<p>When the Delete statement is executed, it executes the statements that will be executed instead of delete statement.<\/p>\n<p>We know that the record with ID value 2 belongs to Nurullah \u00c7AKIR in the table.<\/p>\n<p>Let&#8217;s create a trigger. If the ID value is 2, do not allow deletion. And give a warning that &#8220;Nurullah \u00c7AKIR&#8221; can not be deleted.<\/p>\n<p>At the same time, add a record to the TriggerLog table indicating that you want to delete the record for Nurullah \u00c7AKIR.<\/p>\n<p>If the ID is not set to 2, perform the delete operation.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TRIGGER [dbo].[Trg_InsteadOf_Delete]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ON [dbo].[TriggerOrnegi]\r\nINSTEAD OF DELETE\r\nAS\r\nBEGIN\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DECLARE @ID INT\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SELECT @ID = DELETED.ID\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FROM DELETED\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 IF @ID = 2\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BEGIN\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 RAISERROR('The record of Nurullah \u00c7AKIR can not be deleted.',16 ,1)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ROLLBACK\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 INSERT INTO [dbo].[TriggerLog]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 VALUES(@ID,NULL, 'The record of Nurullah \u00c7AKIR wanted to be deleted.')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 END\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ELSE\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BEGIN\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DELETE FROM [dbo].[TriggerOrnegi]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WHERE ID = @ID\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 INSERT INTO [dbo].[TriggerLog]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 VALUES(@ID,NULL, 'Instead Of Delete')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 END\r\nEND<\/pre>\n<p>Let&#8217;s try to delete the record with ID number 2 belonging to Nurullah \u00c7AKIR named person. Do not forget to delete other triggers first.<\/p>\n<pre class=\"lang:default decode:true\">DELETE FROM [dbo].[TriggerOrnegi] Where ID=2\r\nGO\r\nSelect * FROM [dbo].[TriggerOrnegi]\r\nGO\r\nSelect * FROM [dbo].[TriggerLog]<\/pre>\n<p>When we ran the script, it gave us a message like the following.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/631.png\" width=\"487\" height=\"357\" \/><\/p>\n<p>When we go to the Results tab, we can see that the record has not been deleted and the log record has been saved.<\/p>\n<p>If an attempt was made to delete a record outside ID 2, the deletion would take place.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/348.png\" width=\"547\" height=\"355\" \/><\/p>\n<h2>DDL(Data Definition Language) Trigger:<\/h2>\n<p>It can be triggered when the modification operations on the database are performed.<\/p>\n<p>When creating the trigger, we specify when to trigger it. I gave the database modification procedures a few examples below.<\/p>\n<ul>\n<li>CREATE DATABASE, DROP DATABASE<\/li>\n<li>Create Table, Alter Table, Drop Table<\/li>\n<li>Create Function,Alter Function,Drop Function<\/li>\n<li>Create View,Alter View,Drop View<\/li>\n<li>Create Stored Procedure,Alter Stored Procedure, Drop Stored Procedure<\/li>\n<\/ul>\n<p>To make an example of modifications in the database I create a stored procedure, a view, a function with the following script in our test database.<\/p>\n<pre class=\"lang:default decode:true\">--Creating Sample Stored Procedure.\r\nCREATE PROCEDURE OrnekStoredProcedure\r\nAS\r\nBEGIN\r\nSET NOCOUNT ON;\r\nEND\r\n\r\n--Creating Sample Function\r\nCREATE FUNCTION OrnekFunction(@a int)\r\nRETURNS TABLE\r\nAS\r\nRETURN (SELECT 0 AS d\u00f6necektablo)\r\n\r\n--Creating Sample View\r\nCREATE VIEW [dbo].[OrnekView]\r\nAS\r\nSELECT dbo.TriggerOrnegi.*\r\nFROM\u00a0\u00a0\u00a0\u00a0 dbo.TriggerOrnegi<\/pre>\n<p>After creating our sample objects, create a Database Trigger as follows.<\/p>\n<p>We will define that the trigger will prevent the creation of TABLE, FUNCTION, VIEW or STORED PROCEDURE in this database, and deletion and modification in existing ones.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TRIGGER DDLTriggerOrnek\r\nON DATABASE\r\nFOR CREATE_TABLE,DROP_TABLE, ALTER_TABLE,\r\nCREATE_FUNCTION,ALTER_FUNCTION,DROP_FUNCTION,\r\nCREATE_VIEW,ALTER_VIEW,DROP_VIEW,\r\nCREATE_PROCEDURE,ALTER_PROCEDURE,DROP_PROCEDURE AS\r\nPRINT 'Modifications to this database can not be performed.'\r\nROLLBACK<\/pre>\n<p>After creating the Trigger, you can see the result of deleting, modifying, and creating a new object.<\/p>\n<p>As an example, let&#8217;s try to delete the view we created.<\/p>\n<pre class=\"lang:default decode:true\">DROP VIEW [dbo].[OrnekView]\r\nGO<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/381.png\" width=\"464\" height=\"192\" \/><\/p>\n<p>To find out what you can do with the DDL Trigger, you should run the script below.<\/p>\n<pre class=\"lang:default decode:true \">select * from sys.trigger_event_types<\/pre>\n<h3>Logon Trigger:<\/h3>\n<p>When the user logs in to become a login, the login and password information is checked and then if the connection information is correct, the connection is triggered before it happens.<\/p>\n<p>You can not use this for failed connections. Instead, you should use SQL Server Alerts.<\/p>\n<p>I mentioned this in the article &#8220;<a href=\"http:\/\/dbtut.com\/index.php\/2018\/07\/03\/how-to-send-email-for-failed-logons\/\" target=\"_blank\" rel=\"noopener\">How To Send Email For Failed Logons<\/a>&#8220;.<\/p>\n<p>You can find more detailed information about the alerts in the &#8220;<a href=\"https:\/\/dbtut.com\/index.php\/2018\/07\/06\/always-on-availability-group-alert-system\/\" target=\"_blank\" rel=\"noopener\">Always On Availability Group Alert System<\/a>&#8221; and &#8220;<a href=\"https:\/\/dbtut.com\/index.php\/2018\/07\/09\/sql-server-best-practices-and-configurations-that-need-to-be-made-after-installation\/\" target=\"_blank\" rel=\"noopener\">SQL Server Best Practices and Configurations that need to be made After Installation<\/a>&#8220;.<\/p>\n<p>It can be used to log successful entries or limit the privileges of some of the logins. Let&#8217;s make 2 examples about these two topics.<\/p>\n<h3>Example1:<\/h3>\n<p>We use the following script to create a table to hold successful logins in the master database and log successful entries with the Logon Trigger.<\/p>\n<pre class=\"lang:default decode:true\">CREATE TABLE Login_Info\r\n(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Login_Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 NVARCHAR(256),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Login_Time\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATETIME,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Host_Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 NVARCHAR(128)\r\n)\r\n\r\nCREATE TRIGGER Trigger_Log\r\nON ALL SERVER WITH EXECUTE AS 'sa'\r\nFOR LOGON\r\nAS\r\nBEGIN\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 INSERT INTO master..Login_Info\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SELECT ORIGINAL_LOGIN(), GETDATE(),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 EVENTDATA().value('(\/EVENT_INSTANCE\/ClientHost)[1]','NVARCHAR(128)')\r\nEND\r\n<\/pre>\n<p>You can delete the Logon Trigger with the following script.<\/p>\n<pre class=\"lang:default decode:true \">DROP TRIGGER Trigger_Log ON ALL SERVER<\/pre>\n<h3>Example2:<\/h3>\n<p>We create a login named TestLogin with the following script, and when the session number of this login is 3, we trigger the trigger to prevent it from opening more than 3 connections.<\/p>\n<pre class=\"lang:default decode:true\">USE master;\u00a0\r\nGO\u00a0\r\nCREATE LOGIN TestLogin WITH PASSWORD = 'Test123'\u00a0\u00a0\r\nGO\u00a0\r\nGRANT VIEW SERVER STATE TO TestLogin;\u00a0\r\nGO\u00a0\r\nCREATE TRIGGER Trigger_ConnectionLimit\u00a0\r\nON ALL SERVER\r\nFOR LOGON\u00a0\r\nAS\u00a0\r\nBEGIN\u00a0\r\nIF ORIGINAL_LOGIN()= 'TestLogin' AND\u00a0\r\n\u00a0\u00a0\u00a0 (SELECT COUNT(*) FROM sys.dm_exec_sessions\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WHERE is_user_process = 1 AND\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 original_login_name = 'TestLogin') &gt; 3\u00a0\r\n\u00a0\u00a0\u00a0 ROLLBACK;\u00a0\r\nEND;<\/pre>\n<p>After login with TestLogin, try to open several query screens by clicking new query.<\/p>\n<p>When you try to open the third query screen, it will fail as below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/532.png\" width=\"491\" height=\"143\" \/><\/p>\n<p>You can delete the Logon Trigger with the following script.<\/p>\n<pre class=\"lang:default decode:true \">DROP TRIGGER Trigger_ConnectionLimit ON ALL SERVER<\/pre>\n<p>You can see the Triggers at the table level under Triggers as below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/631-1.png\" width=\"259\" height=\"124\" \/><\/p>\n<p>Database-level triggers can be viewed under Programmability-&gt; Database Triggers as follows.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/239.png\" width=\"250\" height=\"202\" \/><\/p>\n<p>You can see the Triggers at Server Level under Server Objects as below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/389.png\" width=\"276\" height=\"163\" \/><\/p>\n\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_574\" class=\"pvc_stats all  \" data-element-id=\"574\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Trigger is used to trigger another event when an event occurs in the database server. There are 3 types of trigger. 1) DML(Data Manipulation Language) Trigger 2) DDL(Data Definition Language) Trigger 3) Logon Trigger DML(Data Manipulation Language) Trigger: Includes INSERT, UPDATE, and DELETE operations on the database. You can also do things using DML Trigger &hellip;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_574\" class=\"pvc_stats all  \" data-element-id=\"574\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[3],"tags":[670,671,666,667,516,668,669,661,657,656,663,665,655,654,306,662,664,672,677,678,674,673,675,676,658,680,679,660,652,651,653,659,192],"class_list":["post-574","post","type-post","status-publish","format-standard","","category-mssql","tag-after-delete","tag-after-delete-trigger","tag-after-insert","tag-after-insert-trigger","tag-after-trigger","tag-after-update","tag-after-update-trigger","tag-check-constraints","tag-ddl-trigger","tag-ddldata-definition-language-trigger","tag-deleted","tag-deleted-table","tag-dml-trigger","tag-dmldata-manipulation-language-trigger","tag-foreign-key","tag-inserted","tag-inserted-table","tag-instead-of","tag-instead-of-delete","tag-instead-of-delete-trigger","tag-instead-of-insert","tag-instead-of-trigger","tag-instead-of-update","tag-instead-of-update-trigger","tag-logon-trigger","tag-on-all-server","tag-original_login","tag-rimary-key","tag-sql-server-trigger","tag-sql-server-trigger-types","tag-trigger","tag-trigger-types","tag-unique-constraint"],"aioseo_notices":[],"a3_pvc":{"activated":true,"total_views":420,"today_views":0},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Server Trigger Types - Database Tutorials<\/title>\n<meta name=\"description\" content=\"SQL Server Trigger Types\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server Trigger Types - Database Tutorials\" \/>\n<meta property=\"og:description\" content=\"SQL Server Trigger Types\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/\" \/>\n<meta property=\"og:site_name\" content=\"Database Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-02T19:57:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-05T22:38:27+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png\" \/>\n<meta name=\"author\" content=\"dbtut\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"dbtut\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/\"},\"author\":{\"name\":\"dbtut\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/fc047c39e1e53dce28fc4253529ea408\"},\"headline\":\"SQL Server Trigger Types\",\"datePublished\":\"2018-07-02T19:57:04+00:00\",\"dateModified\":\"2021-02-05T22:38:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/\"},\"wordCount\":1527,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png\",\"keywords\":[\"AFTER DELETE\",\"AFTER DELETE Trigger\",\"AFTER INSERT\",\"AFTER INSERT Trigger\",\"AFTER Trigger\",\"AFTER UPDATE\",\"AFTER UPDATE Trigger\",\"CHECK CONSTRAINTS\",\"DDL Trigger\",\"DDL(Data Definition Language) Trigger\",\"deleted\",\"deleted table\",\"DML Trigger\",\"DML(Data Manipulation Language) Trigger\",\"Foreign Key\",\"inserted\",\"inserted table\",\"INSTEAD OF\",\"INSTEAD OF DELETE\",\"INSTEAD OF DELETE Trigger\",\"INSTEAD OF INSERT\",\"INSTEAD OF Trigger\",\"INSTEAD OF UPDATE\",\"INSTEAD OF UPDATE Trigger\",\"Logon Trigger\",\"ON ALL SERVER\",\"ORIGINAL_LOGIN()\",\"RIMARY KEY\",\"SQL Server Trigger\",\"SQL Server Trigger Types\",\"Trigger\",\"Trigger Types\",\"unique constraint\"],\"articleSection\":[\"MSSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/\",\"url\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/\",\"name\":\"SQL Server Trigger Types - Database Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png\",\"datePublished\":\"2018-07-02T19:57:04+00:00\",\"dateModified\":\"2021-02-05T22:38:27+00:00\",\"description\":\"SQL Server Trigger Types\",\"breadcrumb\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#primaryimage\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png\",\"width\":921,\"height\":546},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dbtut.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Trigger Types\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dbtut.com\/#website\",\"url\":\"https:\/\/dbtut.com\/\",\"name\":\"Database Tutorials\",\"description\":\"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux\",\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dbtut.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/dbtut.com\/#organization\",\"name\":\"dbtut\",\"url\":\"https:\/\/dbtut.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"width\":223,\"height\":36,\"caption\":\"dbtut\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/fc047c39e1e53dce28fc4253529ea408\",\"name\":\"dbtut\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c322c32021bf651d9e103b183963c479a9c9791ead0715f4348203496c39aa54?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c322c32021bf651d9e103b183963c479a9c9791ead0715f4348203496c39aa54?s=96&d=mm&r=g\",\"caption\":\"dbtut\"},\"description\":\"We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.\",\"sameAs\":[\"http:\/\/NurullahCAKIR\"],\"url\":\"https:\/\/dbtut.com\/index.php\/author\/dbtut\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Server Trigger Types - Database Tutorials","description":"SQL Server Trigger Types","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:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server Trigger Types - Database Tutorials","og_description":"SQL Server Trigger Types","og_url":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/","og_site_name":"Database Tutorials","article_published_time":"2018-07-02T19:57:04+00:00","article_modified_time":"2021-02-05T22:38:27+00:00","og_image":[{"url":"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png","type":"","width":"","height":""}],"author":"dbtut","twitter_card":"summary_large_image","twitter_misc":{"Written by":"dbtut","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#article","isPartOf":{"@id":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/"},"author":{"name":"dbtut","@id":"https:\/\/dbtut.com\/#\/schema\/person\/fc047c39e1e53dce28fc4253529ea408"},"headline":"SQL Server Trigger Types","datePublished":"2018-07-02T19:57:04+00:00","dateModified":"2021-02-05T22:38:27+00:00","mainEntityOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/"},"wordCount":1527,"commentCount":0,"publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"image":{"@id":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#primaryimage"},"thumbnailUrl":"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png","keywords":["AFTER DELETE","AFTER DELETE Trigger","AFTER INSERT","AFTER INSERT Trigger","AFTER Trigger","AFTER UPDATE","AFTER UPDATE Trigger","CHECK CONSTRAINTS","DDL Trigger","DDL(Data Definition Language) Trigger","deleted","deleted table","DML Trigger","DML(Data Manipulation Language) Trigger","Foreign Key","inserted","inserted table","INSTEAD OF","INSTEAD OF DELETE","INSTEAD OF DELETE Trigger","INSTEAD OF INSERT","INSTEAD OF Trigger","INSTEAD OF UPDATE","INSTEAD OF UPDATE Trigger","Logon Trigger","ON ALL SERVER","ORIGINAL_LOGIN()","RIMARY KEY","SQL Server Trigger","SQL Server Trigger Types","Trigger","Trigger Types","unique constraint"],"articleSection":["MSSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/","url":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/","name":"SQL Server Trigger Types - Database Tutorials","isPartOf":{"@id":"https:\/\/dbtut.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#primaryimage"},"image":{"@id":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#primaryimage"},"thumbnailUrl":"http:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png","datePublished":"2018-07-02T19:57:04+00:00","dateModified":"2021-02-05T22:38:27+00:00","description":"SQL Server Trigger Types","breadcrumb":{"@id":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#primaryimage","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2018\/07\/162.png","width":921,"height":546},{"@type":"BreadcrumbList","@id":"https:\/\/dbtut.com\/index.php\/2018\/07\/02\/sql-server-trigger-types\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dbtut.com\/"},{"@type":"ListItem","position":2,"name":"SQL Server Trigger Types"}]},{"@type":"WebSite","@id":"https:\/\/dbtut.com\/#website","url":"https:\/\/dbtut.com\/","name":"Database Tutorials","description":"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux","publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dbtut.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/dbtut.com\/#organization","name":"dbtut","url":"https:\/\/dbtut.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","width":223,"height":36,"caption":"dbtut"},"image":{"@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/dbtut.com\/#\/schema\/person\/fc047c39e1e53dce28fc4253529ea408","name":"dbtut","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c322c32021bf651d9e103b183963c479a9c9791ead0715f4348203496c39aa54?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322c32021bf651d9e103b183963c479a9c9791ead0715f4348203496c39aa54?s=96&d=mm&r=g","caption":"dbtut"},"description":"We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.","sameAs":["http:\/\/NurullahCAKIR"],"url":"https:\/\/dbtut.com\/index.php\/author\/dbtut\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/comments?post=574"}],"version-history":[{"count":0,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/574\/revisions"}],"wp:attachment":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/media?parent=574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/categories?post=574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/tags?post=574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}