Loading, please wait...

Triggers

Introduction To Triggers In SQL

 

Introduction:
In this article, you will learn, what Triggers are in SQL.

 

In SQL triggers, we can easily access the data from DDL and DML commands. Triggers are also used to store the queries that run automatically like DDL or DML commands. If we are doing any operation on the table with the help of Triggers, it stores the table name in the memory. We can execute here insert and delete statements but first, it creates a table in memory and then performs an operation on Insert and Delete statement. It also includes the data integrity, business logic or the business rule.

 

 

Type of Triggers

We have two types of Triggers in SQL:

 

  • DDL Trigger
  • DML trigger

 

 

 

DDL Triggers

DML works with the create, alter, and drop operations. These are used in SQL database. These Triggers runs after the execution. DDL trigger can be used to detect and control the actions, performed on the server.

 

 

DML Triggers

DML works with the insert, update and deletes operations and it creating the table for the insert, update and delete operations. These are used in the database tables. These Triggers run before the execution.

 

DML Triggers are divided into two parts:

 

  • After Trigger
  • Instead of Trigger

 

After Trigger -
SQL After trigger, when our statement execution is successfully completed, Alter Trigger fires. Alter Trigger executes after an insert, update or delete statement in a table. They are not supported for views.

 

Alter Trigger can be divided into three main parts:

 

  • Alter Insert Trigger.
  • Alter Update Trigger.
  • Alter Delete Trigger.

 

Instead Of Trigger-
In SQL Instead Of trigger, when our query starts the execution, Instead Of Trigger fires. Instead Of Trigger and Alter Trigger are both different, when compared to each other. Alter Trigger fires after the execution instead of firing before the execution. When we will perform Insert and Delete operation on the Instead Of Trigger, it runs successfully but it will not delete the data in an actual table.

 

It can be divided into three main parts:

 

  • Instead of Insert Trigger.
  • Instead of Update Trigger.
  • Instead of Delete Trigger.

 


Summary:
Thus, we learned triggers are used to access the data from SQL commands.