?
Solved

T-SQL syntax to avoid firing a trigger?

Posted on 2008-10-22
4
Medium Priority
?
492 Views
Last Modified: 2012-05-05
Hi there,
I have a field that when it is updated causes a trigger which fires off an email to warn a department of a modification that was made to a field.
However, the department concerned who have the final word also make a change to this field and therefore do not need an email when they perform the change.
Is there any stored procedure syntax which would prevent the 'update trigger'.  This would be my preferred solution.  

However if this cannot be done, how can I test the user account that is being used to update the field so that I can check for this when the trigger fires?
0
Comment
Question by:dgloveruk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 1400 total points
ID: 22776469
You can use the current_user() function inside your trigger and if the user is a particular one, return.


http://msdn.microsoft.com/en-us/library/aa258248(SQL.80).aspx

create trigger tr_Update on MyTble
for update
as
if @@rowcount=0 
  return
 
set nocount on
if current_user() = 'SomeUser'
  return
 
print 'do trigger code here'

Open in new window

0
 

Author Comment

by:dgloveruk
ID: 22776581
Thats great, are you aware of any way to execute the update in t-sql without firing the trigger at all?
If this isn't possible I'll go ahead and award points now.
Thanks in advance!
0
 
LVL 37

Assisted Solution

by:momi_sabag
momi_sabag earned 600 total points
ID: 22776863
there is no way to avoid firing a trigger
the only possible of bypassing the trigger is by using code inside the trigger
0
 

Author Closing Comment

by:dgloveruk
ID: 31508738
Thank you guys!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question