Home > Miscellaneous > Difference between DML Triggers and DDL Triggers in MS SQL Server

Difference between DML Triggers and DDL Triggers in MS SQL Server

A trigger is an event based stored procedure that automatically executes when an event occurs in the database server. DML triggers execute when a user tries to modify data through a data manipulation language (DML) event. DML events are INSERT, UPDATE, or DELETE statements on a table or view. DDL trigger is executed when a database object is created, altered or dropped from the database.

 

Below are the key differences in DDL and DML triggers:

DML Triggers DDL Triggers
Events associated with DML keywords like ‘Insert’, ‘Update’ and ‘Delete’ cause the execution of DML triggers Events associated with DDL keywords like ‘Create’, ‘Alter’ and ‘Drop’ cause the execution of DDL triggers
These triggers can be executed both before and after the ‘Insert’, ‘Update’ and ‘Delete’ events occur. These triggers are executed only after the ‘Create’, ‘Alter’ and ‘Drop’ DDL events are occured.
These triggers are object level triggers and are associated with Tables and Views These triggers are database level triggers and they are directly associated with DDL objects
Magic Tables viz. ‘inserted’ and ‘deleted’ are accessible in DML triggers There are no magic tables in the DDL Triggers

 

Post comments if this helps

This Article is TAGGED in , , , . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">