---
title: "What are Triggers in the Database and how many types of Triggers are in the database and what are the uses of Triggers?"  
description: "What are Triggers in the Database and how many types of Triggers are in the database and what are the uses of Triggers?"  
author: "Ethan Karla"  
published: 2021-09-14  
canonical: https://answers.mindstick.com/qa/93960/what-are-triggers-in-the-database-and-how-many-types-of-triggers-are-in-the-database-and-what-are-the-uses-of-triggers  
category: "database"  
tags: ["database", "database management system"]  
reading_time: 3 minutes  

---

# What are Triggers in the Database and how many types of Triggers are in the database and what are the uses of Triggers?

What are [Triggers](https://www.mindstick.com/articles/337000/what-are-sql-triggers-and-ways-of-using-them-effectively) in the [Database](https://www.mindstick.com/articles/100/windows-service-to-update-record-from-one-database-to-another-after-certain-interval-of-time) and how many types of Triggers are in the database and what are the uses of Triggers?

## Answers

### Answer by Ashutosh Kumar Verma

**SQL Trigger :** Triggers are stored programs, whenever any action in the table such as: - insertion, deletion, update is done, the triggers are executed automatically. Trigger can create for DDL statement means when a DDL statement is perform like as – create, drop, alter then trigger is automatically called. Triggers cannot be called or invoked because whenever a DDL and DML statement is executed, the trigger is executed automatically. **Syntax-** CREATE TRIGGER trigger_name ON table_name AFTER INSERT | AFTER DELETE | AFTER UPDATE AS BEGIN INSERT INTO new_created_table END; **Example:** **Create a table ,** CREATE TABLE Employees( EmpId int not null, EmpName varchar(256), Gender varchar(15), Salery money ); Inserted record in ‘Employees’ table as- ![What are Triggers in the Database and how many types of Triggers are in the database and what are the uses of Triggers?](https://answers.mindstick.com/questionanswer/c9571d5d-dcb4-4303-b06c-8e19c466e33c/images/90ec28ad-7846-4b42-8025-0ea693c72aa0.png) \
Create a another table to store transaction records like the records of INSERT, DELETE, UPDATE on the ‘Employees’ table CREAE TABLE trgTest( ID int not null, Name varchar(256), Gender varchar(15), Salery money ); **Now Create a Trigger:** CREATE TRIGGER trgAfterInsert ON Employees FOR INSERT AS DECLARE @ID INT; DECLARE @Name varchar(256); DECLARE @Gender varchar(15); DECLARE @Salery money; SELECT @ID=i.EmpId FROM inserted i; SELECT @Name=i.EmpName FROM inserted i; SELECT @Gender=i.Gender FROM inserted i; SELECT @Salery=i.Salery FROM inserted i; insert into trgTest( ID, Name, Gender, Salery) Values(@ID, @Name, @Gender, @Salery); print 'After insert trigger fired'; The trigger is fired automatically when record is insert into ‘Employees’ table. **Other example of creating a trigger is as below-** 1- Create a table ‘DemoTrigger’. 2- Create another table ‘TestTrigger’. 3- Create trigger and apply it on First created table as is given in below SQL statement 4- Select all columns from ‘DemoTrigger’ table and insert into ‘TestTrigger’ table through trigger. 5- When you insert any record into DemoTrigger table then trigger send that record into second table ‘TestTrigger’ automatically. CREATE TRIGGER trgTestTrigger ON DemoTrigger FOR INSERT AS DECLARE @ID INT; DECLARE @Name varchar(256); DECLARE @Gender varchar(15); DECLARE @Salary money; SELECT @ID =i.ID FROM inserted i; SELECT @Name =i.trgName FROM inserted i; SELECT @Gender =i.trgGender FROM inserted i; SELECT @Salary =i.trgSalary FROM inserted i; INSERT INTO TestTrigger(ID, Name, Gender, Salary) Values(@ID, @Name, @Gender, @Salary); Here insert a record into ‘DemoTrigger’ like as- insert into DemoTrigger Values(101,'Roman Reigns','Male',150000); When record is inserted into ‘DemoTrigger’ then its trigger automatically fired and insert that record into other table ‘TestTrigger’. ![What are Triggers in the Database and how many types of Triggers are in the database and what are the uses of Triggers?](https://answers.mindstick.com/questionanswer/c9571d5d-dcb4-4303-b06c-8e19c466e33c/images/6ecde60a-1a1d-45f4-a9ed-33c2f9f329df.png) Above table is 'DemoTriger' and the below table is 'TestTrigger'. \
**Types of Trigger:** There are two types of triggers used in SQL Server- **1-** DDL trigger (Data Definition Language). **2-** DML trigger (Data Manipulation Language). **DDL trigger:** In the SQL Server you can create trigger for DDL statement. If when you perform DDL commands then the trigger is automatically called or invoked. The DDL command is like- CREATE, ALTER, DROP. **DML trigger:** In the SQL Server you can create trigger for DML statement. When you perform a DML command then the trigger is invoked automatically. The DML command is like – INSERT, SELECT, DELETE, UPDATE etc. \


---

Original Source: https://answers.mindstick.com/qa/93960/what-are-triggers-in-the-database-and-how-many-types-of-triggers-are-in-the-database-and-what-are-the-uses-of-triggers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
