You can use the sys.triggers
catalog view to return a list of triggers in a database in SQL Server.
This view contains a row for each object that is a trigger, with a type of TR or TA.
Example
Here’s an example of querying sys.triggers
:
SELECT * FROM sys.triggers;
Result (using vertical output):
-[ RECORD 1 ]------------------------- name | trg_Books_UpdateModifiedDate object_id | 1669580986 parent_class | 1 parent_class_desc | OBJECT_OR_COLUMN parent_id | 1605580758 type | TR type_desc | SQL_TRIGGER create_date | 2020-08-16 00:35:09.880 modify_date | 2020-08-16 00:35:09.880 is_ms_shipped | 0 is_disabled | 0 is_not_for_replication | 0 is_instead_of_trigger | 0 (1 row affected)
I used vertical output in this example so that you don’t have to scroll sideways.
In my case, I’ve only got one trigger in this database.
If I switch to a different database, I get the triggers in that database. If the database contains no triggers, then I get no results.
USE WideWorldImporters;
SELECT * FROM sys.triggers;
Result:
Commands completed successfully. (0 rows affected)
Server Triggers
If you need to return a list of server triggers, use sys.server_triggers
instead of sys.triggers
.
That view returns all server-level DDL triggers with object_type of TR or TA.