Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Link Column Of two Table

 
anchit pancholi
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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
 
Zachary Pry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Hi Zachary,

Thanks for such a great help

Thanks
Anchit
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic