Subject | Re: Trigger or Stored Procedure dilemma |
---|---|
Author | andrew_s_vaz |
Post date | 2008-09-12T10:06Z |
> 1. They could deadlock, if it's already possible (without thetriggers) for two concurrent
> transactions to successfully update two or more of the seven tables,for the same PK, without
> conflicting. Example: if you have "people", "addresses", and"phone_numbers", and it's possible for
> two concurrent transactions to modify the same person's information(by only touching
> either "addresses" or "phone_numbers" but leaving "people" alone),then your trigger would cause a
> problem: the two transactions would both insert/update that the"person" (in my example) needed to
> be replicated, and deadlock.limit on the amount of code
>
> 2. Doesn't matter; triggers and stored procedures have the same byte
> you can stuff into them; creating a separate SP just polutes thedatabase namespace, which is
> already too easy to do; an extra procedure call seems unlikely tospeed things up. It wouldn't
> change your concurrency situation at all.concurrency risks.
>
> 3. I think so, yes. It's a lot of tables, but you'll reduce your
> Another choice would be to always insert into the replicationtable, never update; drop the PK
> on the replication table, and use DISTINCT when deciding what topull out of it, and delete the
> replication records as you handle them.guessing it is, from your wording;
>
> This assumes that the "master/detail" relationship is what I'm
> I'm a little worried that a "delete" against a detail record couldmark the master record for
> deletion in the next replication, which doesn't seem appropriate --is it the detail table's FK to
> the master that is put into the replication table, or that table'sPK? And if it's that table's PK,
> how do you differentiate between operations on different tables, toknow what the three PK fields
> mean?move it and its detail rows
>
> So, either:
> - keep a control table for the "master" part of a master/detail, and
> over each time, replacing anything in the replication database forthat master (involves marking
> rows as "bad" on the destination side, updating/inserting andmarking as "good" any data coming
> from the source, then deleting any rows still marked as bad), orchanges occuring, never touching more
> - keep control tables for each table, and replicate the exact
> records than you need to.Thanks for your Input Philip. I see that my design is wrong and I'm
>
> -Philip
going to put more thinking into something better as you advised.
Thanks again for your time.
Andrew