Reply to Re: Foreign key error

Your name:

Reply:


Posted by Andy Hassall on 06/23/06 18:18

On 23 Jun 2006 00:58:49 -0700, jason.m.ho@gmail.com wrote:

>Why does creating the following table give me the error: ERROR 1005
>(HY000): Can't create table (errno: 150)
>
>CREATE TABLE orderProducts (
>orderID integer(10),
>productID integer(10),
>quantity integer(10),
>PRIMARY KEY (orderID, productID),
>FOREIGN KEY (orderID) REFERENCES orders (orderID),
>FOREIGN KEY (productID) REFERENCES products (productID)
>);
>
>Can i not say that attributes that are part of the primary key are also
>foreign keys?

http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html

You'll need an index on productID.
It ought to be able to use the primary key index for orderID, though.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация