Re: Primary and foreign key
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.