473,625 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update statement not to fire trigger

I have a trigger on UPDATE on a table. I'm running some maintenance
UPDATE and DELETE queries which I want the trigger to ignore but at the
same time I want other UPDATE queries that other users might be running
to keep triggering the trigger. Is there a SET statement perhaps that
I could set before my query? Or a clause in the UPDATE statement?

This is on MSSQL 2000 server, on Win2k3

Feb 1 '06 #1
2 10001
Dima Gofman wrote:
I have a trigger on UPDATE on a table. I'm running some maintenance
UPDATE and DELETE queries which I want the trigger to ignore but at the
same time I want other UPDATE queries that other users might be running
to keep triggering the trigger. Is there a SET statement perhaps that
I could set before my query? Or a clause in the UPDATE statement?

This is on MSSQL 2000 server, on Win2k3


Not without rewriting the trigger. If the business rule isn't universal
then it shouldn't be in a trigger. IMO that consideration should be the
first thing you think about when deciding whether to create the
trigger.

You can do this:

BEGIN TRAN
ALTER TABLE tbl DISABLE TRIGGER ALL
....

ALTER TABLE tbl ENABLE TRIGGER ALL
COMMIT TRAN

but other users will be blocked for the duration of the transaction.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

Feb 1 '06 #2
Dima Gofman (dg@cfa-solutions.com) writes:
I have a trigger on UPDATE on a table. I'm running some maintenance
UPDATE and DELETE queries which I want the trigger to ignore but at the
same time I want other UPDATE queries that other users might be running
to keep triggering the trigger. Is there a SET statement perhaps that
I could set before my query? Or a clause in the UPDATE statement?

This is on MSSQL 2000 server, on Win2k3


And how do you know that you don't need to fire the trigger? Because
you are to violate some business rules? :-)

In addition to David's suggestion to use ALTER TABLE DISABLE TRIGGER, a
trick is to have this check in the trigger:

IF object_id('temp db..#trigger$sk ip') IS NOT NULL
RETURN

Before you run your maintenance operation, you would create this table.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Feb 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
11594
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to be updated when a group of items is copied. I can successfully do this with cursors, but am experimenting with a way to do it with a single update statement. I have verified that each row being returned to the Update statement (in an...
5
9826
by: Wing | last post by:
Hi all, I am writing a function that can change the value "Quantity" in the selected row of MS SQL table "shoppingCart", my code is showing below ------------------------------------------------------ static void addQuantity(int rowNum, int oldQuantity) { int newQuantity = oldQuantity++; SqlConnection thisConnection = new SqlConnection (@"Data Source=(local);Integrated Security=SSPI;" +
1
3086
by: amitbadgi | last post by:
HI i am getting the foll error while conv an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in UPDATE statement. Source Error: Line 112: MM_editCmd.ActiveConnection = MM_editConnection Line 113: MM_editCmd.CommandText = MM_editQuery Line 114: MM_editCmd.Execute
6
2684
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the person wants to receive a newsletter and 0 no, don't want to receive it. Now.....when trying to create an UPDATE statement I am running into problems writing the code for it. I had issues before with missing commas but now that the commas are there...
3
1578
by: rola | last post by:
Hi Group! I am having a problem of using SUM under UPDATE statement. I understand that SQL does not allow me to use SUM in UPDATE, but unfortunately, I can not find a way to get around it. Can someone please give me some idea? Thanks a million! --Here is the criteria: Under the same PORTFOLIO_ID, if the ACCOUNT_OPENDATE is in the same month as the PORTFOLIO_OPENDATE, then sum the account_openamt for the
19
8359
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without FOR UPDATE, it is fine and no error. I also tried Set objRs = objConn.Execute("SELECT * FROM EMP UPDATE OF EMPNO"), but it still couldn't help. any ideas? I tried to search in the web but couldn't find similar
2
1844
by: aaa1234 | last post by:
HI, I am writing a trigger to update table b, depending on updates on table a. table a and b has 300 columns. I want to update only those columns which are changed by update statement like, lets say col is a column in table a my trigger body will be UPDATE TRIGGER ON A OLD AS O NEW AS N if ( O.col <> N.co) then update b set col = some value
10
3563
by: JohnO | last post by:
Hi All, This question is related to iSeries V5R4 and db2. I want to implement an AFTER DELETE trigger to save the deleted rows to an archive table, I initially defined it as a FOR EACH STATEMENT trigger that would insert all the deleted rows in one operation like this: CREATE TRIGGER MyTable_TD
10
11517
by: gyanendar | last post by:
Hi All, I want to access new value after upadate in statement level trigger. But in my query I am getting old values. Here is the Trigger Code: CREATE OR REPLACE TRIGGER TEST_TRIGGER AFTER UPDATE OF col3 on table_gyan DECLARE PRAGMA AUTONOMOUS_TRANSACTION; v_count NUMBER:=0;
0
8251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8688
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8352
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7178
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.