-
Notifications
You must be signed in to change notification settings - Fork 0
/
exo3.sql
83 lines (60 loc) · 2.75 KB
/
exo3.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#------------------------------------------------------------
# Script MySQL.
#------------------------------------------------------------
#------------------------------------------------------------
# Table: catégorie
#------------------------------------------------------------
CREATE TABLE categorie(
code_categorie Varchar (50) NOT NULL ,
intitule_categorie Text NOT NULL
,CONSTRAINT categorie_PK PRIMARY KEY (code_categorie)
)ENGINE=InnoDB;
#------------------------------------------------------------
# Table: marques
#------------------------------------------------------------
CREATE TABLE marques(
code_marque Varchar (50) NOT NULL ,
nom_marque Varchar (50) NOT NULL
,CONSTRAINT marques_PK PRIMARY KEY (code_marque)
)ENGINE=InnoDB;
#------------------------------------------------------------
# Table: modèles
#------------------------------------------------------------
CREATE TABLE modeles(
code_modele Varchar (50) NOT NULL ,
nom_modele Varchar (50) NOT NULL ,
annee_modele Date NOT NULL ,
code_marque Varchar (50) NOT NULL
,CONSTRAINT modeles_PK PRIMARY KEY (code_modele)
,CONSTRAINT modeles_marques_FK FOREIGN KEY (code_marque) REFERENCES marques(code_marque)
)ENGINE=InnoDB;
#------------------------------------------------------------
# Table: types pièce
#------------------------------------------------------------
CREATE TABLE types_piece(
code_type_piece Int Auto_increment NOT NULL ,
code_categorie Varchar (50) NOT NULL
,CONSTRAINT types_piece_PK PRIMARY KEY (code_type_piece)
,CONSTRAINT types_piece_categorie_FK FOREIGN KEY (code_categorie) REFERENCES categorie(code_categorie)
)ENGINE=InnoDB;
#------------------------------------------------------------
# Table: pièces
#------------------------------------------------------------
CREATE TABLE pieces(
code_piece Varchar (50) NOT NULL ,
etat Varchar (50) NOT NULL ,
date_recap Date NOT NULL ,
code_type_piece Int NOT NULL
,CONSTRAINT pieces_PK PRIMARY KEY (code_piece)
,CONSTRAINT pieces_types_piece_FK FOREIGN KEY (code_type_piece) REFERENCES types_piece(code_type_piece)
)ENGINE=InnoDB;
#------------------------------------------------------------
# Table: convient à
#------------------------------------------------------------
CREATE TABLE convient_a(
code_modele Varchar (50) NOT NULL ,
code_type_piece Int NOT NULL
,CONSTRAINT convient_a_PK PRIMARY KEY (code_modele,code_type_piece)
,CONSTRAINT convient_a_modeles_FK FOREIGN KEY (code_modele) REFERENCES modeles(code_modele)
,CONSTRAINT convient_a_types_piece0_FK FOREIGN KEY (code_type_piece) REFERENCES types_piece(code_type_piece)
)ENGINE=InnoDB;