What are SQL Server triggers?
They are a particular type of stored procedure that automatically runs when an event occurs in the database.
Why should you care about them?
The delete, update, and insert operations against theses objects incur extra costs, which affects performance.
Massive bulks and recursive triggers can cause severe performance.
How can I find the triggers?
Triggers on a table
- Open SSMS, expand the Databases and choose your database.
- Click on the target table and Expand the Triggers to list all items.
Triggers on a database
- Open SSMS, expand the Databases and choose your database.
- Click on Programmability and
- Choose Database Triggers to list all items.
How to identify the triggers
You can use the query below to identify all the triggers in your database tables:
SELECT table_name = OBJECT_NAME(parent_object_id)
, trigger_name = name
, trigger_owner = USER_NAME(schema_id)
, OBJECTPROPERTY(object_id, 'ExecIsUpdateTrigger') AS isupdate
, OBJECTPROPERTY(object_id, 'ExecIsDeleteTrigger') AS isdelete
, OBJECTPROPERTY(object_id, 'ExecIsInsertTrigger') AS isinsert
, OBJECTPROPERTY(object_id, 'ExecIsAfterTrigger') AS isafter
, OBJECTPROPERTY(object_id, 'ExecIsInsteadOfTrigger') AS isinsteadof
, CASE OBJECTPROPERTY(object_id, 'ExecIsTriggerDisabled')
WHEN 1
THEN 'Disabled'
ELSE 'Enabled'
END AS STATUS FROM sys.objects WHERE type = 'TR'
ORDER BY OBJECT_NAME(parent_object_id)
How to fix them?
Triggers are not always bad, but they must be used wisely.
- Look into triggers with the highest resource consumption.
- See if they can be replaced by another method.
- If not, see if the trigger code can be optimized.