- Introduction To SQL
- RDBMS
- Data Integrity and Normalization
- Function in SQL
- SQL Syntax
- Data Types
- Operators
- SQL Expressions
- Database
- Tables
- Query
- Select Query
- Update query
- Delete Query
- Distinct Keyword
- Sorting
- Null Values
- Alias Syntax
- Drop a Table
- Alter Table
- Truncate Command
- Select Query
- Update query
- Delete Query
- Distinct Keyword
- Sorting
- Null Values
- Alias Syntax
- Drop a Table
- Alter Table
- Truncate Command
- Select Query
- Update query
- Delete Query
- Distinct Keyword
- Sorting
- Null Values
- Alias Syntax
- Drop a Table
- Alter Table
- Truncate Command
- Select Query
- Update query
- Delete Query
- Distinct Keyword
- Sorting
- Null Values
- Alias Syntax
- Drop a Table
- Alter Table
- Truncate Command
- Select Query
- Update query
- Delete Query
- Distinct Keyword
- Sorting
- Null Values
- Alias Syntax
- Drop a Table
- Alter Table
- Truncate Command
- Select Query
- Update query
- Delete Query
- Distinct Keyword
- Sorting
- Null Values
- Alias Syntax
- Drop a Table
- Alter Table
- Truncate Command
- Select Query
- Update query
- Delete Query
- Distinct Keyword
- Sorting
- Null Values
- Alias Syntax
- Drop a Table
- Alter Table
- Truncate Command
- Select Query
- Update query
- Delete Query
- Distinct Keyword
- Sorting
- Null Values
- Alias Syntax
- Drop a Table
- Alter Table
- Truncate Command
- Select Query
- Update query
- Delete Query
- Distinct Keyword
- Sorting
- Null Values
- Alias Syntax
- Drop a Table
- Alter Table
- Truncate Command
- Select Query
- Update query
- Delete Query
- Distinct Keyword
- Sorting
- Null Values
- Alias Syntax
- Drop a Table
- Alter Table
- Truncate Command
- Clauses
- Like Clause
- Top Clause
- Order By Clause
- Group By Clause
- Except Clause
- Intersect Clause
- Union Clause
- Union All Clause
- Having Clause
- Like Clause
- Top Clause
- Order By Clause
- Group By Clause
- Except Clause
- Intersect Clause
- Union Clause
- Union All Clause
- Having Clause
- Like Clause
- Top Clause
- Order By Clause
- Group By Clause
- Except Clause
- Intersect Clause
- Union Clause
- Union All Clause
- Having Clause
- Like Clause
- Top Clause
- Order By Clause
- Group By Clause
- Except Clause
- Intersect Clause
- Union Clause
- Union All Clause
- Having Clause
- Like Clause
- Top Clause
- Order By Clause
- Group By Clause
- Except Clause
- Intersect Clause
- Union Clause
- Union All Clause
- Having Clause
- Like Clause
- Top Clause
- Order By Clause
- Group By Clause
- Except Clause
- Intersect Clause
- Union Clause
- Union All Clause
- Having Clause
- Like Clause
- Top Clause
- Order By Clause
- Group By Clause
- Except Clause
- Intersect Clause
- Union Clause
- Union All Clause
- Having Clause
- Like Clause
- Top Clause
- Order By Clause
- Group By Clause
- Except Clause
- Intersect Clause
- Union Clause
- Union All Clause
- Having Clause
- Like Clause
- Top Clause
- Order By Clause
- Group By Clause
- Except Clause
- Intersect Clause
- Union Clause
- Union All Clause
- Having Clause
- SQL Constraints
- Joins
- Indexes
- Views
- Transactions
- Date Functions
- Sequences
- Sub Queries
- Handling Duplicates
- SQL Injection
- Stored Procedure
- Triggers
DML Triggers
How to use DML Triggers in SQL
Introduction:
In this article, you will learn types of DML triggers in SQL.
DML triggers are divided into two main types:
- After Triggers
- Instead Of Triggers
After Triggers
The SQL After trigger is the one, where our statement execution is successfully completed, Alter trigger fires. They are not supported for views.
After Triggers can be divided into three parts as:
- After Insert Trigger
- After Update Trigger
- After Delete Trigger
First, we will create a new database and a new table.
- After Insert Trigger
Step 1: After creating a table, we will create a trigger to insert the data.
Step 2: Insert some data in this table.
Step 3: The output is:
- After Update Trigger
Step 1: Now, we will create a trigger to update the data.
Step 2: Here, we can see our command ran successfully.
Step 3: Thus, we will update the rows in this table.
- After Delete Trigger
Step 1: Now, we will create a trigger to delete the data.
Step 2: Here, we can see our command ran successfully.
Instead Of Triggers
SQL Instead Of Trigger is the one, when our query starts execution, Instead Of Trigger fires. When we will perform Insert and Delete operation on Instead Of Trigger, it runs successfully but does not delete the data in the actual table.
Instead Of Triggers can be divided into three parts as:
- Instead Of Insert Trigger
- Instead Of Update Trigger
- Instead Of Delete Trigger
- Instead Of Insert Trigger
Step 1: After creating a table, we will create a trigger to insert the data.
Step 2: Here, we can see our command ran successfully.
Step 3: Now, we will insert the data into this table.
Step 4: The output is:
- Instead Of Update Trigger
Step 1: Now, we will create a trigger to update the data.
Step 2: Here, we can see our command ran successfully.
Step 3: Now, we update the rows in this table.
- Instead Of Delete Trigger
Step 1: Now, we will create a trigger to delete the data.
Step 2: Here, we can see our command ran successfully.
Summary:
Thus, we learned the use of After Tiggers and Instead Of Triggers in SQL.