1 pièce(s) jointe(s)
Les clés étrangères en mysql
Bonjour. Je suis en train de créer un e base de données mais j'ai des problèmes avec des clés étrangères. Voici le code :
Code:
CREATE DATABASE gest_note;
Code:
1 2 3 4
| CREATE TABLE options(
num_opt INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
lib_opt VARCHAR(200) NOT NULL
) TYPE=INNODB; |
Code:
1 2 3 4
| CREATE TABLE annee_etude(
num_annee SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
lib_annee VARCHAR(200) NOT NULL
) TYPE=INNODB; |
#TABLE CONCERNER#
Code:
1 2 3 4 5 6 7 8 9
| CREATE TABLE concerner(
num_opt INT UNSIGNED,
num_annee INT UNSIGNED NOT NULL,
PRIMARY KEY(num_opt, num_annee),
index(num_annee),
index(num_opt),
FOREIGN KEY(num_opt) REFERENCES options(num_opt),
FOREIGN KEY(num_annee) REFERENCES annee_etude(num_annee)
)TYPE=INNODB; |
Code:
1 2 3 4
| CREATE TABLE semestre(
numsem INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
lib_sem VARCHAR(200) NOT NULL
) TYPE=INNODB; |
#TABLE MODULES#
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| CREATE TABLE modules(
num_mod INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
lib_mod VARCHAR(200) NOT NULL,
num_annee INT UNSIGNED NOT NULL,
num_opt INT UNSIGNED,
num_sem INT UNSIGNED NOT NULL,
index(num_annee),
index(num_opt),
index(num_sem),
FOREIGN KEY(num_annee) REFERENCES annee_etude(num_annee),
FOREIGN KEY(num_opt) REFERENCES options(num_opt),
FOREIGN KEY(num_sem) REFERENCES semestre(num_sem)
) TYPE=INNODB; |
#TABLE UNITE_ENSEIGN#
Code:
1 2 3 4 5 6 7
| CREATE TABLE unite_enseig(
num_ue INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
lib_ue VARCHAR(200) NOT NULL,
num_mod INT UNSIGNED NOT NULL,
index(num_mod),
FOREIGN KEY(num_mod) REFERENCES modules(num_mod)
) TYPE=INNODB; |
Code:
1 2 3 4 5
| CREATE TABLE etudiant(
num_etud INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
nom VARCHAR(200) NOT NULL,
prenoms VARCHAR(200) NOT NULL
) TYPE=INNODB; |
#TABLE AVOIR#
Code:
1 2 3 4 5 6 7 8 9 10
| CREATE TABLE avoir(
num_etud INT UNSIGNED NOT NULL,
num_ue INT UNSIGNED NOT NULL,
note DECIMAL(4,2)
PRIMARY KEY(num_etud,num_ue),
index(num_etud),
index(num_ue),
FOREIGN KEY(num_etud) REFERENCES etudiant(num_etud),
FOREIGN KEY(num_ue) REFERENCES unite_enseig(num_ue)
) TYPE=INNODB; |
Est-ce quelqu'un pourrait m'aider a corriger ce code; en fait l'erreur se trouve au niveau des tables