List:General Discussion« Previous MessageNext Message »
From:Victoria Reznichenko Date:February 16 2004 9:58am
Subject:Re: FOEIGN KEY
View as plain text  
"Mulugeta Maru" <mulugetamaru@stripped> wrote:
> Can a field in one table be a foreign key of another table's field which is 
> also a foreign key of a third table?
> 

Sure.
For example:

mysql> CREATE TABLE t1 (
    ->   id int NOT NULL default '0',
    ->   PRIMARY KEY  (id)
    -> ) TYPE=InnoDB;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE t2 (
    ->   id int NOT NULL default '0',
    ->   pid int default NULL,
    ->   PRIMARY KEY  (id),
    ->   KEY (pid),
    ->   FOREIGN KEY (pid) REFERENCES t1 (id)
    -> ) TYPE=InnoDB;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE t3 (
    ->   id int NOT NULL default '0',
    ->   pid int default NULL,
    ->   PRIMARY KEY  (id),
    ->   KEY (pid),
    ->   FOREIGN KEY (pid) REFERENCES t2 (pid)
    -> ) TYPE=InnoDB;
Query OK, 0 rows affected (0.00 sec)



-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Victoria Reznichenko
 / /|_/ / // /\ \/ /_/ / /__   Victoria.Reznichenko@stripped
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
       <___/   www.mysql.com




Thread
FOEIGN KEYMulugeta Maru15 Feb
  • Re: FOEIGN KEYVictoria Reznichenko16 Feb
    • Re: FOEIGN KEYVictoria Reznichenko17 Feb