MS SQL Server Concepts and Programming Question:
Download Job Interview Questions and Answers PDF
How To List All Triggers in the Database with sys.triggers in MS SQL Server?
Answer:
If you want to list all triggers defined in the current database, you can use the catalog view, sys.triggers, as shown in the following tutorial example:
USE GlobalGuideLineDatabase;
GO
CREATE TRIGGER new_user ON ggl_users
AFTER INSERT
AS
PRINT 'New users added.';
GO
SELECT * FROM sys.triggers
GO
<pre>name object_id parent_id type type_desc
------------ ----------- ----------- ---- ------------
dml_message 690101499 674101442 TR SQL_TRIGGER
new_user 706101556 674101442 TR SQL_TRIGGER </pre>
The result shows that there are 2 triggers defined in GlobalGuideLineDatabase.
USE GlobalGuideLineDatabase;
GO
CREATE TRIGGER new_user ON ggl_users
AFTER INSERT
AS
PRINT 'New users added.';
GO
SELECT * FROM sys.triggers
GO
<pre>name object_id parent_id type type_desc
------------ ----------- ----------- ---- ------------
dml_message 690101499 674101442 TR SQL_TRIGGER
new_user 706101556 674101442 TR SQL_TRIGGER </pre>
The result shows that there are 2 triggers defined in GlobalGuideLineDatabase.
Download MS SQL Server Interview Questions And Answers
PDF
Previous Question | Next Question |
How To Test a DML Trigger in MS SQL Server? | How To Modify Existing Triggers using "ALTER TRIGGER"? |