Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    many to many relations

    maybe a dumb question, but how do I make relations with Mysql?

    these are my tables:
    owner(onwerid, name, ...)
    equipment(Serialnr, type...)

    between owner and equipment, there is a many to many relation, so I need an other table:
    equipment_owner(ownerid, serialnr, date)

    how do I make those relations with mysql?
    this is how I've done it, is this correct:
    PHP Code:
    $query="create table equipment(
    serialnr integer not null auto_increment,
    type text,
    primary key(serienr))"
    ;

    $query="create table owner(
    ownerid integer not null auto_increment,
    name text,
    primary key(klantid))"
    ;

    $query="create table equipment_owner(
    serialnr integer not null ,
    ownerid integer not null ,
    date timestamp(14),
    KEY ownerid_serialnr (serialnr,ownerid))"

    I'm not sure about the table equipment_owner. How do you make the link with the serialnr of the table equipment and the serialnr of ownerid_serialnr (same with ownerid).

    thanks

    --maes
    Last edited by maes; 11-21-2002 at 08:20 PM.

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    MySQL does not support entity relationship constraints. So I think what you have there is all you need to create and start using the tables.

    You will have to keep track of the data yourself as MySQL has no way to tell you if there are any broken relationshipe (unless you check yourself...).


  •  

    Posting Permissions

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