...

many to many relations

maes
11-21-2002, 08:17 PM
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:
$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

Dylan Leblanc
11-26-2002, 12:54 AM
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...).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum