473,657 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Triggers fire before commits... and can not be rolled back?!?

I know even less about databases than I thought... I always thought
that the idea behind a transaction was that the actual table in
question does NOT get updated until a commit is issued (either
implicitly or explicitly). However, when I create an "after update"
trigger on table X, and then perform an update inside of a transaction,
the trigger fires IMMEDIATELY, even before I issue the commit or
rollback.

Is this a quirk of DB2? Is there a way to provision triggers that fire
only after a committed table change is made?
Thanks in advance for any advice or similar experiences.

Nov 12 '05 #1
4 6998
>> However, when I create an "after update"
trigger on table X, and then perform an update inside of a transaction,
the trigger fires IMMEDIATELY, even before I issue the commit or
rollback.
.... <<

that is a correct behavior, as specified in ANSI standard.

Having triggers do too much is a typical mistake. Triggers should be
left to handle only simple tasks. Why don't you explain what you need
to accomplish - we might help to find another way to implement it

Nov 12 '05 #2
good idea... here's what i'm trying to accomplish:

App commits update to database#1
App gets back result and proceeds with whatever is next
Update to database#1 causes data to be written to either log file or
database#2, completely unbundled and on a different time scale than
database#1

i was trying to avoid having the App do BOTH updates, which is
possible. also, i thought triggers are a good way of centralizing a
change, e.g. trigger on insert to send an email is a nice,
single-location of logic that will execute regardless of if there are
dozens of apps who perform an insert.

given my objectives, do you see any way to use triggers?

as always, thanks in advance for this excellent feedback...

ak************@ yahoo.com wrote:
However, when I create an "after update"
trigger on table X, and then perform an update inside of a

transaction, the trigger fires IMMEDIATELY, even before I issue the commit or
rollback.
... <<

that is a correct behavior, as specified in ANSI standard.

Having triggers do too much is a typical mistake. Triggers should be
left to handle only simple tasks. Why don't you explain what you need
to accomplish - we might help to find another way to implement it


Nov 12 '05 #3
>> Update to database#1 causes data to be written to ... database#2,
completely unbundled and on a different time scale than
database#1
.... <<

that's exactly what replication is used for

Nov 12 '05 #4
ak wrote:
Update to database#1 causes data to be written to ... database#2,

completely unbundled and on a different time scale than
database#1
... <<
that's exactly what replication is used for


personally, I also like simple asynchronous processes run outside the
database for this scenario: a small python/ruby/kshell/etc script run
by cron every 5 minutes that looks for any of these cases and performs
the appropriate action.

really simple to write & maintain, only downside is that failures won't
be visible to owner of the transaction to report back to you - so a
simple logging & alerting mechanism is also required.

kenfar

Nov 12 '05 #5

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

Similar topics

11
6623
by: raulgz | last post by:
I need audit triggers that change columns value in the same record that fire trigger. I need how to do.. Thanks..
1
1637
by: Mike Miller | last post by:
When you import data using DTS into a table that has triggers - do the triggers fire off if there are triggers for on insert or on after insert? Thanks, --Micah
7
1817
by: Sjaak van Esdonk | last post by:
Hi all, i'm trying to find a solution for the following problem: I have two different database called A and B. On database A runs an application call AA. Some information from the database A is used in database B. Currently triggers are being used to update the data on database B when anything changes on database A. Working this way has the the problem that when database B is offline
3
4413
by: Jonathan Bishop | last post by:
Hi. We are using MSDE2000 on a Point of Sale application. We need to keep a copy of a few key tables as up to date as possible for backup purposes. We are looking at using triggers over the source tables to update the target tables using a linked servers setup. Distributed Transaction Coordinator is running on both source and target servers. This following create command:
3
1763
by: Curtis Gilchrist | last post by:
I'm trying my hand at triggers and it doesn't seem to be working for me. I have a very simple database that consists of one table: Employees. I want to create a trigger that will limit the EMP_TITLE field to either Ms., Mr., or Mrs. I am using the following code: CREATE trigger triTitleCheck ON employee FOR insert, update AS declare @v1 varchar
4
7493
by: Tzar | last post by:
Hi, I am new to the db2 world. How do you handle exceptions within triggers. I was trying to port following trigger from Oracle: CREATE TRIGGER DB2ADMIN.TEST_ARI AFTER INSERT ON DB2ADMIN.TEST REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL
0
1670
by: Private Pyle | last post by:
Version 8.1 fixpack 5, AIX 5.1 32-bit I have a situation where I want to use a merge statement to perform insert else update logic to move data from one table to another. I have a working merge statement that is doing updates and inserts and all is well. Here's where the fun comes in.... Now I have a requirement to define a pair of after triggers on the subject table for the merge. So I have an "after update" and an "after insert"...
2
2301
by: Karl O. Pinc | last post by:
Hi, I don't suppose that the todo item: Referential Integrity o Add deferred trigger queue file (Jan) Means that there will be a statement like: CREATE TRIGGER ... FOR EACH TRANSACTION
7
3753
by: ajomara | last post by:
Hai everyboby i am new to this group,can one help me in triggers could anyone help in the fallowing lines "Database triggers can be system triggers on a database or a schema. With a database,triggers fire for each event for all users. With a schema,triggers fire for each event for that specifiv user." What is the difference between trigger in a database or in a schema? thank u in advance.
0
8823
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
8503
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
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
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...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.