Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.4K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 468 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Changing the same column in two tables at the same time

user635344
Member Posts: 30 Blue Ribbon
Hi,
Oracle 10g2
I have 2 tables:
1. tab1 : Stores people info
2. tab2 : Stores people insurance info
Both have an address field.
What I need to do is when tab1.address is updated I want the tab2.address to update automatically and
when tab2.address is updated I want tab1.address to update.
Is there a way to do this using triggers without having these triggers mutate?
Thanks,
Oleg
Edited by: user635344 on Oct 8, 2009 11:04 AM
Oracle 10g2
I have 2 tables:
1. tab1 : Stores people info
2. tab2 : Stores people insurance info
Both have an address field.
What I need to do is when tab1.address is updated I want the tab2.address to update automatically and
when tab2.address is updated I want tab1.address to update.
Is there a way to do this using triggers without having these triggers mutate?
Thanks,
Oleg
Edited by: user635344 on Oct 8, 2009 11:04 AM
Answers
-
I know this may not answer your question, but I have the following suggestions (in order of how I would do it):
<ol><li>Analyze the current design and see if there is a need to store two separate address fields that have the same data in them.</li>
<li>If you can't modify the design I would personally have the application call a stored procedure/package that I wrote that has the proper update statements in it because I don't like triggers.</li></ol> -
Centinul wrote:I'm with Centinul...
... I don't like triggers.
I don't like triggers that perform DML-statements (which would be the case if you do this with triggers).
I have no issues with triggers that perform Queries (usually to validate (non-declarable) constraints).
Toon -
Toon Koppelaars wrote:Good point!
I have no issues with triggers that perform Queries (usually to validate (non-declarable) constraints).(Had to return the compliment)
-
Agreeing fully with Centinul and Toon in the first place here, I'd make PEOPLE_ADDRESS an entity on it's own, with proper primary and foreign keys.
It's a quite common design (that's an understatement).
Your requirement is sort of 'screaming for that'.
Trying to get this done using triggers will get you/the users of the application in trouble sooner or later.
Why store the same data in more than one table?
You more or less want to 'update cascade' regardless whether parent or child table gets updated.
When such a requirement arises: just adjust your datamodel. -
Hi,
It's working application.
Development team requires to add some functionality.
So I need to support the same value in 2 tables at the same time.
Thank you for your help,
Oleg -
user635344 wrote:but not working very well?
It's working application.
Add the table, move the data from both tables into this new table and create foreign keys... if you are required to add some functionality, it might as well be this. -
Unless you can do what I suggested above (see #1, or #2) I think your "SOL."
Regularly defined triggers will fail with a mutating table error and autonomous triggers will generate a deadlock condition. -
Hi,So I need to support the same value in 2 tables at the same time.I'm very sorry, Oleg, but that goes into some modeling rules/principles.
If there's no possibility to put ADDRESS into a separate entity, in the end it's asking for trouble.
A 'trigger solution' will kill you or the ones maintaining that code after you.
You (or your superior) are asking for an update casecade that works both ways: parent => child and child => parent.
That's a design flaw.
It just won't work, it won't perform, it is asking for trouble.
Fix the datamodel.
Perhaps this might be of use:
http://tkyte.blogspot.com/search?q=update+cascade (scroll down a bit)
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:5773459616034
edit
Don't even try it. Just fix the model.
Edited by: hoek on Oct 8, 2009 9:00 PM -
user635344 wrote:Too bad is has to be "at the same time"...
So I need to support the same value in 2 tables at the same time.
Otherwise you could have opted for some daily batch-job that synchronized the lot
(saying this without enough detailed knowledge of your requirements).
What you are trying to implement is called Master-Master replication. A very tough problem to get 100% right. And certainly not one that we can quickly and easily provide you with example triggercode for. -
Toon Koppelaars wrote:This begs the question which table is the "master" table if they can both update each other based on the OP?
Otherwise you could have opted for some daily batch-job that synchronized the lot
(saying this without enough detailed knowledge of your requirements).
This discussion has been closed.