Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How can I use a database event


How can I use a database event

Author
Message
MikeLPlates
MikeLPlates
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 123
Hi

Apologies if I'm posting in the wrong place - but this seemed the closest.

What I've done.....

When a loading process is finished, it updates the final stage status of a record to Completed.
I've put in a place a trigger which then inserts a row into another database on this status change
This then fires off 3 triggers to perform certain subsequent activity - in effect 3 procedures.

The issue I have it that this is all part of the original transaction. (In this case, if the two databases were out of sync, I'm not bothered, I have a recovery mechanism.) My concern, is that whilst the 3 triggered procedures are running on Database B, I could be holding locks on the original database.

Ideally, if using Ingres. I would write the three procedures to register for a Database event 'File Completed'. The trigger on the Database Insert table would raise the event 'File Completed' with the associated ID, and the original transaction would commit.

I think a similar thing could be done in Oracle wih Advanced Queueing.

I thought I might be able to use this solution with SQL Server - but it seems to be only DDL. Does anyone have any elegant solutions?

Regards

Mike
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52960 Visits: 40375
If you consider the way you'd do it in Ingres "elegant", then why not just do it that way? Write the 3 stored procedures.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Steve Jones
Steve Jones
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: Administrators
Points: 41129 Visits: 18871
I don't think there's a more elegant way. You could use the DTC (distributed transaction coordinator), but it would hold locks until things were committed, and if your link was down, you couldn't commit anything.

The slightly more elegant way in SQL is to use Service Broker to Q the event and have it picked up by the other database and take action there. that way if there were some comm issue, you could still commit the event in the first database/table and when things were working, it would occur in the second one. That leaves you some loose coupling, but the chance that things are out of sync for some time.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Jack Corbett
  Jack Corbett
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12492 Visits: 14863
I agree with Steve that Service Broker is probably a way to do what you are looking at doing.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search