Sql-server – How to make trigger code execute only for a specific application

sql serversql-server-2008-r2

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.

Best Answer

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... 
    If app_name() = 'something' 
        put code here