Solved

T-SQL syntax to avoid firing a trigger?

Posted on 2008-10-22
4
454 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
  • 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

776 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