Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2013
    Posts
    9

    Unanswered: Link Column Of two Table

    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

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    When adding in the referential integrity constraint be sure to add in on delete/update cascade.

    Code:
    ALTER TABLE `Table` ADD CONSTRAINT `Table_ibfk_1` FOREIGN KEY (`parent`) REFERENCES `Table` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
    This will only work one way i.e. on the master table you perform an update and it will reflect this change in the child. However, this will not work if you update a child record to another value (remember that the constraint will force the child entry to update to something that already exists).
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •