May 15, 2022

Trigger in SQL Server

Hello  guys, In this blog, I am going to explain you about a Trigger and  how to perform a trigger inside the database.

Trigger-

A SQL trigger is a database object which fires when an event occurs in a database. We can execute a SQL query that will "do something" in a database when a change occurs on a database table such as a record is inserted or updated or deleted.

Different Types of Triggers-

DML Trigger

DDL Trigger

DML Trigger-

DML triggers is a special type of stored procedure that automatically takes effect when a data manipulation language (DML) event takes place that affects the table or view defined in the trigger. DML events include INSERT, UPDATE, or DELETE statements.


DDL Trigger-

The DDL triggers in SQL Server are fired in response to a variety of data definition language (DDL) events such as Create, Alter, Drop, Grant, and Revoke (Table, Function, Index, Stored Procedure, etc…). That means DDL triggers in SQL Server are working on a database.

DDL triggers are introduced from SQL Server 2005 version which will be used to restrict the DDL operations such as CREATE, ALTER and DROP commands.


How to implement trigger inside the database-


First you have to select the database and inside the database you have to create a table 









·       After that create  a trigger inside the database and then you have to create a procedure by writing a syntax as given below,



·       After that delete some data from the table



·       After that whatever the data you have deleted from the table it is shown into the delete log table.





·       Here, name of the user has been shown who deleted the data.



No comments:

Post a Comment

If you have any doubt or question, please contact us.