List:General Discussion« Previous MessageNext Message »
From:Egor Egorov Date:March 8 2003 9:13am
Subject:re: Multiple foreign keys?
View as plain text  
On Saturday 08 March 2003 02:27, Daevid Vincent wrote:

> Can I have multiple foreign keys in a table? Like this... I ask because I
> can't seem to get it to work. Errno: 150.

Yes, you can. Check that all tables are InnoDB, that columns have the same 
type and so on ..

>
> CREATE TABLE `dept_table` (
>   `dept_id` mediumint(8) unsigned NOT NULL auto_increment,
>   `dept_timestamp` timestamp(14) NOT NULL,
>   `dept_company_table_id` mediumint(8) unsigned NOT NULL default '0'
> REFERENCES company_table(company_id),
>   `dept_rep_table_id` smallint(8) unsigned default NULL REFERENCES
> rep_table(rep_id),
>   `dept_name` varchar(255) NOT NULL default '',
>   `dept_SCM_10` date NOT NULL default '0000-00-00',
>   `dept_SCM_20` date NOT NULL default '0000-00-00',
>   `dept_SCM_40` date NOT NULL default '0000-00-00',
>   `dept_SCM_60` date NOT NULL default '0000-00-00',
>   `dept_SCM_80` date NOT NULL default '0000-00-00',
>   `dept_SCM_90` date NOT NULL default '0000-00-00',
>   `dept_SCM_100` date NOT NULL default '0000-00-00',
>   `dept_notes` text NOT NULL,
>   PRIMARY KEY  (`dept_id`),
>   KEY `dept_company_table_id` (`dept_company_table_id`),
>   KEY `dept_rep_table_id` (`dept_rep_table_id`),
>   FOREIGN KEY (dept_company_table_id) REFERENCES company_table(company_id)
> ON DELETE CASCADE,
>   FOREIGN KEY (dept_rep_table_id) REFERENCES rep_table(rep_id) ON DELETE
> SET NULL
> ) TYPE=InnoDB;




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



Thread
Foreign keys and being FIRST indexDaevid Vincent6 Mar
  • Re: Foreign keys and being FIRST indexDan Nelson6 Mar
    • RE: Foreign keys and being FIRST indexDaevid Vincent6 Mar
      • Re: Foreign keys and being FIRST indexDan Nelson6 Mar
      • RE: Foreign keys and being FIRST indexKeith C. Ivey6 Mar
        • Multiple foreign keys?Daevid Vincent8 Mar
          • re: Multiple foreign keys?Egor Egorov8 Mar
  • Re: Foreign keys and being FIRST indexWilliam R. Mussatto6 Mar