How to relate between two tables in Phpmyadmin

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samuel123
    New Member
    • Nov 2007
    • 7

    How to relate between two tables in Phpmyadmin

    Dear All,

    Greetings!

    I have problem that how to relate between two table in phpmyadmin.

    Say I have two tables,

    project
    -------
    user_id int(11) pk
    title varchar(20)

    commitment
    -------------
    commitment_id int pk
    user_id int fk

    Now, how to relate user_id fields of those two tables..?
    Your help will be greatly appreciated.

    Thank you so much for your help.
    Samuel
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    You need to run the query to relate the tables e.g.
    [CODE=mysql]ALTER TABLE commitment ADD FOREIGN KEY (user_id) REFERENCES project(user_id );[/CODE]
    Read the MySQL Manual about foreign key constraints.

    Comment

    • samuel123
      New Member
      • Nov 2007
      • 7

      #3
      Hi,

      Greetings!
      Thank you so much for your help on relating the two tables. I was really struggling on this. I would greatly appreciate your kind help. I will try to impliment this.

      One more Question:

      For e.g, I have got 6 tables which are related like pk and fk. Do I have to write ALTER TABLE" while showing relation one at a time?


      Once again, thank you for your kind help

      Samuel

      Comment

      Working...