> Unfortunately this goes well beyond the scope of my original question.
> Although the inputs that you all have provided thus far have been a very
> good read, I still don't grasp the concept of defining a relationship. Is
> it simply referring to a primary key in a field other than the one where
the
> key was defined? Or is there some other way to define a key that I don't
> see? All I'm looking for is a simple example, syntax excerpt, etc...that
> shows me (only the "slow learner" level) exactly how to define a
> relationship.
> Unfortunately this goes well beyond the scope of my original question.
> Although the inputs that you all have provided thus far have been a very
> good read, I still don't grasp the concept of defining a relationship. Is
> it simply referring to a primary key in a field other than the one where
the
> key was defined? Or is there some other way to define a key that I don't
> see? All I'm looking for is a simple example, syntax excerpt, etc...that
> shows me (only the "slow learner" level) exactly how to define a
> relationship.
CREATE TABLE parent (
parent_id INT UNSIGNED NOT NULL PRIMARY KEY
) TYPE=innodb;
CREATE TABLE child (
child_id INT UNSIGNED NOT NULL PRIMARY KEY,
parent_id INT UNSIGNED NOT NULL,
INDEX ( parent_id ),
FOREIGN KEY ( parent_id ) REFERENCES parent( parent_id )
) TYPE=innodb;
CREATE TABLE grandchild (
grandchild_id INT UNSIGNED NOT NULL PRIMARY KEY,
child_id INT UNSIGNED NOT NULL,
INDEX ( child_id ),
FOREIGN KEY ( child_id ) REFERENCES child( child_id )
) TYPE=innodb;
To see the relationships at work, try to insert into grandchild a child_id
that doesn't exist in child, or try to insert into child a parent_id that
doesn't exist in parent.
hth
PB
-----
filter fodder: mysql