snippetsqlMinor
How to get the definition of a database trigger?
Viewed 0 times
definitionthetriggerdatabasegethow
Problem
when I run the following script in one of my databases:
when I try to find out about sys.triggers
Contains a row for each object that is a trigger, with a type of TR or
TA. DML trigger names are schema-scoped and, therefore, are visible in
sys.objects. DDL trigger names are scoped by the parent entity and are
only visible in this view.
How then, do I get the database triggers definition?
SELECT * FROM SYS.triggerswhen I try to find out about sys.triggers
Contains a row for each object that is a trigger, with a type of TR or
TA. DML trigger names are schema-scoped and, therefore, are visible in
sys.objects. DDL trigger names are scoped by the parent entity and are
only visible in this view.
How then, do I get the database triggers definition?
Solution
You can use
Shameless copy and paste example from the docs:
The following example returns the definition of a user-defined
trigger, uAddress, in the Person schema. The built-in function
OBJECT_ID is used to return the object ID of the trigger to the
OBJECT_DEFINITION statement.
OBJECT_DEFINITION(). Shameless copy and paste example from the docs:
The following example returns the definition of a user-defined
trigger, uAddress, in the Person schema. The built-in function
OBJECT_ID is used to return the object ID of the trigger to the
OBJECT_DEFINITION statement.
USE AdventureWorks2012;
GO
SELECT OBJECT_DEFINITION (OBJECT_ID(N'Person.uAddress')) AS [Trigger Definition];
GOCode Snippets
USE AdventureWorks2012;
GO
SELECT OBJECT_DEFINITION (OBJECT_ID(N'Person.uAddress')) AS [Trigger Definition];
GOContext
StackExchange Database Administrators Q#214503, answer score: 2
Revisions (0)
No revisions yet.