SQL Server triggers are special stored procedures that are executed automatically in response to the database object, database, and server events. SQL Server provides three type of triggers:
- Data manipulation language (DML) triggers which are invoked automatically in response to
INSERT
,UPDATE
, andDELETE
events against tables. - Data definition language (DDL) triggers which fire in response to
CREATE
,ALTER
, andDROP
statements. DDL triggers also fire in response to some system stored procedures that perform DDL-like operations. - Logon triggers which fire in response to
LOGON
events
In this section, you will learn how to effectively use triggers in SQL Server.
- Creating a trigger in SQL Server – show you how to create a trigger in response to insert and delete events.
- Creating an INSTEAD OF trigger – learn about the
INSTEAD OF
trigger and its practical applications. - Creating a DDL trigger – learn how to create a DDL trigger to monitor the changes made to the structures of database objects such as tables, views, and indexes.
- Disabling triggers – learn how to disable a trigger of a table temporarily so that it does not fire when associated events occur.
- Enabling triggers – show you how to enable a trigger.
- Viewing the definition of a trigger – provide you with various ways to view the definition of a trigger.
- Listing all triggers in SQL Server – show you how to list all triggers in a SQL Server by querying data from the sys.triggers view.
- Removing triggers – guide you how to drop one or more existing trigger.