473,320 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using triggers

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
or nu fully synchronized with database A error appear in the
application AA.

What i want to do is create a mutation log table and make the triggers
on the A database write their info into this table. On that table i
then want to build another trigger which updates the B database.

Will this work (e.a. will the transaction be splitted) and is this the
best solution or can i try something else.

I already thought of doing an import on the mutationlog table every
minute but i actually do not want to do that.
Jul 20 '05 #1
7 1790
SQLServer Replication will do this for you without triggers. If you haven't
already considered that then lookup the Replication topic in Books Online.

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
On 21 Jun 2004 08:43:32 -0700, Sjaak van Esdonk wrote:

(snip)
Will this work (e.a. will the transaction be splitted)


Hi Sjaak,

In addition to David's suggestion: the answer to this question is "no". No
matter how many tables are updated and how many triggers are fired, an
atomic operation will always remain atomic.
Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #3
Thx both, but i think the problem is more complex so i'll try to be
more specific.

The data in database B which comes from Database A is not just a copy
of a table. The triggers which are being fired on the A database
execute some procedures to convert the data in the correct form for
database B. I do not think this will be possible with replication (is
it?). What i would like to have working is the following:

Trigger on table A in database A which writes the new record to table
B in database A. Now i want a trigger on table B which writes the
records (with convert) to database B. When the trigger on table B
fails no record should be written to database B but an e-mail should
be send to someone. The trigger on table A must have worked and
written its data in table B.

I tried to build the code for this problem but am not able to handle
the error in the trigger on Table B. This causes the the trigger on
table A to fail when the trigger on table B fails.
Jul 20 '05 #4
Hi

If Trigger B fails the whole transaction will fail. The only way I can think
of getting around this is to have the transformation external to the
transaction, say a frequently running job, or a computed column.. Without
knowing your code it is hard to suggest anything else.

John
"Sjaak van Esdonk" <sj************@hotmail.com> wrote in message
news:74**************************@posting.google.c om...
Thx both, but i think the problem is more complex so i'll try to be
more specific.

The data in database B which comes from Database A is not just a copy
of a table. The triggers which are being fired on the A database
execute some procedures to convert the data in the correct form for
database B. I do not think this will be possible with replication (is
it?). What i would like to have working is the following:

Trigger on table A in database A which writes the new record to table
B in database A. Now i want a trigger on table B which writes the
records (with convert) to database B. When the trigger on table B
fails no record should be written to database B but an e-mail should
be send to someone. The trigger on table A must have worked and
written its data in table B.

I tried to build the code for this problem but am not able to handle
the error in the trigger on Table B. This causes the the trigger on
table A to fail when the trigger on table B fails.

Jul 20 '05 #5
On 22 Jun 2004 01:04:58 -0700, Sjaak van Esdonk wrote:
Thx both, but i think the problem is more complex so i'll try to be
more specific.

The data in database B which comes from Database A is not just a copy
of a table. The triggers which are being fired on the A database
execute some procedures to convert the data in the correct form for
database B. I do not think this will be possible with replication (is
it?). What i would like to have working is the following:

Trigger on table A in database A which writes the new record to table
B in database A. Now i want a trigger on table B which writes the
records (with convert) to database B. When the trigger on table B
fails no record should be written to database B but an e-mail should
be send to someone. The trigger on table A must have worked and
written its data in table B.

I tried to build the code for this problem but am not able to handle
the error in the trigger on Table B. This causes the the trigger on
table A to fail when the trigger on table B fails.


Hi Sjaak,

As John and I already pointed oout, this will not work. If a trigger
fails, the complete transaction is rolled back. That's how SQL Server
guards data integrity.

I see two possible solutions for you:

1. Find out a non-destructive way to test if database B is avvailable, so
that your code won't ROLLBACK when it isn't. Use the results of that test
to choose between updating the table or sending the e-mail. I'm not
experienced with cross-database work, so I can't help you with this.

2. (My preferred solution). Create a copy of the database B table in
database A. Use triggers to keep the contents of the table in database A
current. Use SQL Server replication to replicate changes to this table to
database B.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #6
Sjaak van Esdonk (sj************@hotmail.com) writes:
Thx both, but i think the problem is more complex so i'll try to be
more specific.

The data in database B which comes from Database A is not just a copy
of a table. The triggers which are being fired on the A database
execute some procedures to convert the data in the correct form for
database B. I do not think this will be possible with replication (is
it?). What i would like to have working is the following:

Trigger on table A in database A which writes the new record to table
B in database A. Now i want a trigger on table B which writes the
records (with convert) to database B. When the trigger on table B
fails no record should be written to database B but an e-mail should
be send to someone. The trigger on table A must have worked and
written its data in table B.

I tried to build the code for this problem but am not able to handle
the error in the trigger on Table B. This causes the the trigger on
table A to fail when the trigger on table B fails.


As pointed out by John and Hugo, an error in a trigger causes the entire
batch to fail.

Replication is certainly an option. You place a copy of the table in A
in the B database. You set up replication between those two tables. Then
you have a trigger on the replicated table that updates the final target
table. The advantage here is that the transaction will eventually be
applied to B, but necessarily not directly.

Since replication is quite complex, it may be an overkill for this
case, and you may prefer to roll your own, by having the trigger to
write to a queue table, and have a job that scans this table to send
it to B.

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #7
thx all for the response .. i am using a copy of the table right now
to solve my problem ...
Jul 20 '05 #8

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

Similar topics

11
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
by: tim.pascoe | last post by:
I'm trying to generate scrips for a database, and everything so far has worked fine, except for the triggers. When I try and script existing triggers, all I get is a blank file - no SQL script. I...
0
by: Dave Sisk | last post by:
Hi Folks: I've got this scenario: User table/file....external triggers declared for *AFTER *INSERT, *AFTER *UPDATE, and *BEFORE *DELETE. The 3 external triggers call a SQLRPG ILE stub...
5
by: Bruce | last post by:
I have several user defined functions which are referenced in triggers and views. For software upgrades, I need to be able to drop the triggers and views which reference these user defined...
1
by: Michael | last post by:
I want to insert a row into an ITEM table if certain SKUs are inserted. There are two triggers where each looks for a particular SKU and inserts the appropriate matching row in the same table. ...
0
by: Bruno Lavoie | last post by:
Hello, i'm etablishing a naming convention for a new project under postgresql. For tables, sequences, views, that's ok! I used good naming conventions for this in the past and i'll keep these...
2
by: lakuma | last post by:
Hi, I have a table called A (say) with columns called name, place, animal and thing. I would want to write an on insert trigger on this table, which would create a table with the name of the...
0
debasisdas
by: debasisdas | last post by:
trigger sample code Ex#10 ======================= INSTEAD OF TRIGGER ---------------------------------------- create or replace trigger mytrig instead of delete or insert or update on eview...
4
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
8
by: moondaddy | last post by:
I'm posting code for a user control ( FunctionConnectorSelector) below which has 3 content controls in it. each content control uses a style from a resource dictionary merged into the app.xaml...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.