MySQL Forums
Forum List  »  InnoDB

Re: Primary and foreign key
Posted by: Vanessa Réty
Date: July 16, 2005 03:22AM

OK,

At first, thank you for giving me the easiest way to access to the command line for MySQL. Before that, I opened the command line in Windows and I entered the way to the bin directory and the command to connect to the MySQL Server.

So, here is the SQL that creates the first table CONTACTS

CREATE TABLE `contacts` (
`pays` varchar(45) default NULL,
`civilite` varchar(45) default NULL,
`prenom` varchar(45) default NULL,
`nom` varchar(45) default NULL,
`tel_bureau` varchar(45) default NULL,
`email` varchar(45) default NULL,
`commentaires` varchar(255) default NULL,
`tel_perso` varchar(45) default NULL,
`fax` varchar(45) default NULL,
`mobile` varchar(45) default NULL,
`adresse1` varchar(100) default NULL,
`adresse2` varchar(100) default NULL,
`code_postal` int(10) unsigned default NULL,
`ville` varchar(45) default NULL,
`numero` int(10) unsigned NOT NULL auto_increment,
`statut` varchar(45) default NULL,
`num_interet` int(10) unsigned default NULL,
`num_provenance` int(10) unsigned default NULL,
`num_service` int(10) unsigned default NULL,
`num_fonction` int(10) unsigned default NULL,
PRIMARY KEY (`numero`),
KEY `FK_contacts_1` (`num_interet`),
KEY `FK_contacts_2` (`num_provenance`),
KEY `FK_contacts_3` (`num_service`),
KEY `FK_contacts_4` (`num_fonction`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1


The second table SOCIETES :

CREATE TABLE `societes` (
`nom` varchar(45) default NULL,
`tel` varchar(45) default NULL,
`fax` varchar(45) default NULL,
`email` varchar(100) default NULL,
`adresse1` varchar(255) default NULL,
`adresse2` varchar(255) default NULL,
`code_postal` varchar(45) default NULL,
`ville` varchar(45) default NULL,
`pays` varchar(45) default NULL,
`commentaires` varchar(255) default NULL,
`numero` int(10) unsigned NOT NULL auto_increment,
`num_interet` int(10) unsigned default NULL,
`num_provenance` int(10) unsigned default NULL,
`statut` varchar(45) default NULL,
PRIMARY KEY (`numero`),
KEY `FK_societes_1` (`num_interet`),
KEY `FK_societes_2` (`num_provenance`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1


The third table SOCIETES_CONTACTS which is based on the two previous :

CREATE TABLE `societes_contacts` (
`num_societe` int(10) unsigned NOT NULL default '0',
`num_contact` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`num_societe`,`num_contact`),
KEY `FK_societes_contacts_2` (`num_contact`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='table qui affecte les contacts a
ux sociÚtÚs; InnoDB free: '


So, If I have composed primary key in the third table, I can't create the first foreign key which refered to the table SOCIETES.
It gives me a no error message but the foreign key is not created.

Options: ReplyQuote


Subject
Views
Written By
Posted
11666
July 15, 2005 11:36AM
5142
July 15, 2005 04:12PM
Re: Primary and foreign key
7830
July 16, 2005 03:22AM
4369
July 16, 2005 04:41AM
3931
July 16, 2005 06:45AM
3970
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.