Trigger & Send Mail Question

  • I have a question in regard to identifying the database. I have a trigger which sends an email to a user notifying them an action needs to be taken on their part. I only want to send the email if the event occurred in the production database. Does anyone know of a way for me to capture this information ? I know I could disable the trigger in the test database and this would quickly solve my problem, but I am hoping to find the requested resolution.

    Thanx!

  • This seems a trivial sort of request - there must be a good reason for it? The simple answer is that you need a parameters table and a column in there which identifies the system as being either production or development or test - I assume you have three. Then read that in the trigger and act accordingly...

    Simon

  • Thank You for your suggestion.

    Actually I have a production and a test database, not a production, test and development system. My question, which wasn't intended to annoy, was whether it is possible to identify which database the trigger fired in, and if the database id is the id of the production database, then send the email to the user. I like keeping my test & production databases in sync, therefore, I didn't want to disable the trigger in the test database, and I also don't want users trying to take action when something occurred in the test database.

  • You could use something like this:

    if (select min(dbid) from master..sysprocesses where spid=@@spid)=<your production database id here>

    xp_sendmail ...

  • Hey Great! That's exactly what I was looking for, THANX!!!!

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply