SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql enforce relationships

    How can I enforce relationships in mysql? For example, I want "link" two fields together (pkey in one table with fkey in another table) so that it is impossible to insert a record which has an invalid value for a foreign key.

    Is this possible in phpmyadmin?
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't unless you use InnoDB tables. You can still set foreign key constraints in your DDL, but tables other than InnoDB tables won't check the constraint.

  3. #3
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so I changed all my table types to innodb. What else do I need to do?
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  4. #4
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just write your DDL with the foreign key constraints. Or did you want to know the syntax?

  5. #5
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help. Once I changed to innodb table types, I can make the relationships by clicking "Relation View" in phpmyadmin.
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.


Bookmarks

Posting Permissions

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