MySQL Forums
Forum List  »  InnoDB

Re: Primary and foreign key
Posted by: Trudy Pelzer
Date: July 25, 2005 06:04PM

Bonjour Vanessa,

The explanation for the problem you are experiencing is that a FOREIGN
KEY must exactly match the columns of the referenced PRIMARY KEY.
In your third table, you are attempting to create:

FOREIGN KEY (`num_contact`) REFERENCES `societes_contacts` (`num_societe`,`num_contact`)

which is illegal SQL syntax.

The rules are:
- The number of columns that make up a FOREIGN KEY must match the
number of columns in the referenced PRIMARY KEY
- The data type of each column in the FOREIGN KEY must be the same
as the data type of the matching referenced PRIMARY KEY column.

Also, as Mr Bouman points out, the storage engine used must be InnoDB.

Trudy Pelzer, Engineering Project Manager
MySQL AB, www.mysql.com

Are you MySQL certified? www.mysql.com/certification

Options: ReplyQuote


Subject
Views
Written By
Posted
11678
July 15, 2005 11:36AM
5150
July 15, 2005 04:12PM
7837
July 16, 2005 03:22AM
4376
July 16, 2005 04:41AM
3936
July 16, 2005 06:45AM
Re: Primary and foreign key
3975
July 25, 2005 06:04PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.