• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Link Column Of two Table

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to link two column of a two different table, if i update column of first table then it should automatically update to other table like :-
Master Table :- product_id, volume.
Child Table :- product_id,volume.

Master table product_id is FOREIGN KEY for child table.

is it possible if i update volume of Master table and it will automatically reflect in child table as well (and vise-versa)?

Thanks
Anchit
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Anchit,

If I understood your question correctly - SQL Triggers should satisfy your need.

If you are using Oracle Database - you can read Oracle Documentation Oracle PL/SQL Triggers

Not every Database out there supports triggers the same way. It would be easier to give you any further advice regarding it once you've share Database vendor you are using.
 
anchit pancholi
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Zachary,

Thanks for reply.

I am using MYSQL.

Thanks
Anchit.
 
Zachary Pry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Anchit,

MySQL supports triggers as well MySQL Create Trigger.

Also here is good Tutorial.

Hope it helps.
 
anchit pancholi
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Zachary,

Thanks for such a great help

Thanks
Anchit
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do I understand it right, that the volume in a child record should always be the same as the volume in the master record? And then you update a child of the master record, the other children of the same master record (the child's "siblings") should be updated as well?

If this is so, the best thing to do would be to remove the volume column from the child table altogether. If you need to read the volume together with other attributes of the child table, you'll use joins. You might need to modify your business logic to some extent (modifying the volume in the child record might need a rethought), but your data model will not have a flaw that needs fixing with triggers.
 
reply
    Bookmark Topic Watch Topic
  • New Topic