A trigger is a sort of stored procedure that is triggered when an event happens in the database server. There are 3 types of triggers as described below:
DML Triggers: DML triggers are triggered when a user attempts to edit data using a data manipulation language (DML) event. These triggers are triggered anytime any eligible event such as INSERT, UPDATE or DELETE occurs, regardless of whether or not table or view rows are affected.
DDL Triggers: DDL triggers are executed in response to certain data definition language (DDL) events. These events are associated with CREATE, ALTER, and DROP statements, as well as some system (built-in) stored procedures that do DDL-like activities.
Logon Triggers: Logon triggers are fired in response to the LOGON event, which is generated when a user’s session is created. Triggers can be produced directly from Transact-SQL statements or from methods of assemblies created in the Microsoft.NET Framework common language runtime (CLR) and uploaded to a SQL Server instance.
ARGUMENTS
BEFORE TRIGGERS: The “Before triggers” are used to change or validate record values before to saving them to the database. This means triggers are executed before data is committed to the database.
FOR / AFTER TRIGGERS: After triggers are used to retrieve system-set field values (such as a record’s Id or LastModifiedDate field) and to affect changes in other records. These triggers are typically used to keep track of the history of each row in a critical/transactional database.
INSTEAD OF TRIGGERS: An SQL trigger that is executed “instead of” a DML statement is known as an INSTEAD OF trigger. There is absolutely no actual insert, remove, or update activity. Instead, it carries out other commands listed in the trigger.
Please see the related topics on this blog for further information about triggers, as well as sample data and examples.
One comment