HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to get the definition of a database trigger?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
definitionthetriggerdatabasegethow

Problem

when I run the following script in one of my databases:

SELECT * FROM SYS.triggers


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?

Solution

You can use 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];   
GO

Code Snippets

USE AdventureWorks2012;  
GO  
SELECT OBJECT_DEFINITION (OBJECT_ID(N'Person.uAddress')) AS [Trigger Definition];   
GO

Context

StackExchange Database Administrators Q#214503, answer score: 2

Revisions (0)

No revisions yet.