"A Trigger is a Database object just like a stored procedure or we can say it is a special kind of Stored Procedure which fires when an event occurs in a database.".
Difference between Stored Procedure and trigger:
Triggers fire implicitly while Stored Procedures fire explicitly.
Type of Triggers:
There are two types of Triggers:
- DDL Trigger
- DML trigger
DDl Triggers:
They fire in response to DDL (Data Definition Language) command events that start with Create, Alter and Drop. Like Create_table, Create_view, drop_table, Drop_view and Alter_table.
Code of DDL Trigger:
create trigger saftey
on database
for
create_table,alter_table,drop_table
as
print'you can not create ,drop and alter table in this database'
rollback;
DML Triggers:
They fire in response to DML (Data Manipulation Language) command events that start with with Insert, Update and Delete. Like insert_table, Update_view and Delete_table.
Code of DML Trigger:
create trigger deep
on emp