Foreign key et référence
Résolu
cascad
Messages postés
2
Date d'inscription
Statut
Membre
Dernière intervention
-
cascad Messages postés 2 Date d'inscription Statut Membre Dernière intervention -
cascad Messages postés 2 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
En regardant des exemples de création de tables MySQL, je vois que la contrainte FOREIGN KEY n'est pas toujours liée à une contrainte PRIMARY KEY d'une autre table, je vois qu'elle peut également être définie pour référencer les colonnes d'une contrainte UNIQUE d'une autre table.
Par exemple dans la table ARBRE ci-dessous, je pourrais apparemment écrire "FOREIGN KEY (ARBRE_CATEGORIE_ID) REFERENCES ARBRE_CATEGORIE (Arbre_Categorie_Name) ON DELETE CASCADE ON UPDATE CASCADE" au lieu de "FOREIGN KEY (ARBRE_CATEGORIE_ID) REFERENCES ARBRE_CATEGORIE (ARBRE_CATEGORIE_ID) ON DELETE CASCADE ON UPDATE CASCADE".
create table ARBRE
(
ARBRE_ID integer not null auto_increment,
Arbre_Name varchar(100) binary not null,
Arbre_Description TEXT(500),
primary key (ARBRE_ID),
unique (ARBRE_ID,Arbre_Name),
INDEX (ARBRE_CATEGORIE_ID),
FOREIGN KEY (ARBRE_CATEGORIE_ID) REFERENCES ARBRE_CATEGORIE (ARBRE_CATEGORIE_ID) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB;
create table ARBRE_CATEGORIE
(
ARBRE_CATEGORIE_ID integer not null auto_increment,
Arbre_Categorie_Name varchar(100) binary not null,
Arbre_Categorie_Description TEXT(500),
primary key (ARBRE_CATEGORIE_ID),
unique (ARBRE_CATEGORIE_ID,Arbre_Categorie_Name),
) ENGINE = InnoDB;
Donc ma question est : Y-a-t-il un avantage (une optimisation) à écrire la contrainte "FOREIGN KEY" d'une manière plutôt que l'autre ?
En regardant des exemples de création de tables MySQL, je vois que la contrainte FOREIGN KEY n'est pas toujours liée à une contrainte PRIMARY KEY d'une autre table, je vois qu'elle peut également être définie pour référencer les colonnes d'une contrainte UNIQUE d'une autre table.
Par exemple dans la table ARBRE ci-dessous, je pourrais apparemment écrire "FOREIGN KEY (ARBRE_CATEGORIE_ID) REFERENCES ARBRE_CATEGORIE (Arbre_Categorie_Name) ON DELETE CASCADE ON UPDATE CASCADE" au lieu de "FOREIGN KEY (ARBRE_CATEGORIE_ID) REFERENCES ARBRE_CATEGORIE (ARBRE_CATEGORIE_ID) ON DELETE CASCADE ON UPDATE CASCADE".
create table ARBRE
(
ARBRE_ID integer not null auto_increment,
Arbre_Name varchar(100) binary not null,
Arbre_Description TEXT(500),
primary key (ARBRE_ID),
unique (ARBRE_ID,Arbre_Name),
INDEX (ARBRE_CATEGORIE_ID),
FOREIGN KEY (ARBRE_CATEGORIE_ID) REFERENCES ARBRE_CATEGORIE (ARBRE_CATEGORIE_ID) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB;
create table ARBRE_CATEGORIE
(
ARBRE_CATEGORIE_ID integer not null auto_increment,
Arbre_Categorie_Name varchar(100) binary not null,
Arbre_Categorie_Description TEXT(500),
primary key (ARBRE_CATEGORIE_ID),
unique (ARBRE_CATEGORIE_ID,Arbre_Categorie_Name),
) ENGINE = InnoDB;
Donc ma question est : Y-a-t-il un avantage (une optimisation) à écrire la contrainte "FOREIGN KEY" d'une manière plutôt que l'autre ?
A voir également:
- Foreign key et référence
- Key windows 10 - Guide
- Reference pto - Accueil - Box & Connexion Internet
- Wic reset key 16 characters free ✓ - Forum Imprimante
- Show key plus - Télécharger - Utilitaires
- Press the esc key for startup menu - Forum Matériel & Système