Solved

T-SQL syntax to avoid firing a trigger?

Posted on 2008-10-22
4
487 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 350 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 150 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

691 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