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

How to make trigger code execute only for a specific application?

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

Problem

I was wondering if it is possible to enable a trigger just for my current application and not for any sql executed against the table.

The situation:

There are two applications working on the same database. App1 and App2.

I have a trigger on 'MyTable' which should only be fired when App1 is executing a query, but not when App2 is doing so.

Solution

While not a good design, it is doable. You'll need to put logic in the trigger so it causes the code to only be executed when the correct application is connected.

Create trigger... 
As
    If app_name() = 'something' 
    begin 
        put code here 
    end

Code Snippets

Create trigger... 
As
    If app_name() = 'something' 
    begin 
        put code here 
    end

Context

StackExchange Database Administrators Q#44752, answer score: 10

Revisions (0)

No revisions yet.