-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script_MPD_bibliotheque_Alain_NGABO.sql
135 lines (113 loc) · 4.97 KB
/
Script_MPD_bibliotheque_Alain_NGABO.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
drop database if exists bibliothèque;
create database if not exists bibliothèque;
USE `bibliothèque` ;
-- -----------------------------------------------------
-- Table `bibliothèque`.`auteur`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `bibliothèque`.`auteur` (
`idauteur` VARCHAR(30) NOT NULL,
`nom` VARCHAR(30) NULL DEFAULT NULL,
`prenom` VARCHAR(30) NULL DEFAULT NULL,
`adresse` VARCHAR(30) NULL DEFAULT NULL,
`telephone` INT NULL DEFAULT NULL,
`sexe` VARCHAR(10) NULL DEFAULT NULL,
`jourdenaissance` VARCHAR(30) NULL DEFAULT NULL,
`isbn` INT NOT NULL
)
;
-- -----------------------------------------------------
-- Table `bibliothèque`.`editeur`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `bibliothèque`.`editeur` (
`idediteur` VARCHAR(30) NOT NULL,
`nom` VARCHAR(30) NULL DEFAULT NULL,
`adresse` VARCHAR(30) NULL DEFAULT NULL,
`telephone` INT NULL DEFAULT NULL
)
;
-- -----------------------------------------------------
-- Table `bibliothèque`.`fichiersabonnes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `bibliothèque`.`fichiersabonnes` (
`numeromatricule` VARCHAR(30) NOT NULL,
`nom` VARCHAR(30) NULL DEFAULT NULL,
`adresse` VARCHAR(30) NULL DEFAULT NULL,
`telephone` INT NULL DEFAULT NULL,
`sexe` VARCHAR(10) NULL DEFAULT NULL,
`jourdenaissance` VARCHAR(30) NULL DEFAULT NULL,
`datedadhesion` VARCHAR(30) NULL DEFAULT NULL,
`categorieprofessionnelle` VARCHAR(30) NULL DEFAULT NULL,
`historiqueemprunt` VARCHAR(30) NULL DEFAULT NULL
)
;
-- -----------------------------------------------------
-- Table `bibliothèque`.`motscles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `bibliothèque`.`motscles` (
`idmotscles` VARCHAR(30) NOT NULL,
`isbn` INT NOT NULL
)
;
-- -----------------------------------------------------
-- Table `bibliothèque`.`livre`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `bibliothèque`.`livre` (
`isbn` INT NOT NULL,
`titre` VARCHAR(30) NULL DEFAULT NULL,
`theme` VARCHAR(30) NULL DEFAULT NULL,
`langue` VARCHAR(10) NULL DEFAULT NULL,
`anneedecriture` INT NULL DEFAULT NULL,
`id_auteur` VARCHAR(30) NULL DEFAULT NULL,
`id_motscles` VARCHAR(30) NULL DEFAULT NULL
)
;
-- -----------------------------------------------------
-- Table `bibliothèque`.`exemplairelivre`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `bibliothèque`.`exemplairelivre` (
`coderayon` VARCHAR(30) NOT NULL,
`codecatalogue` VARCHAR(30) NULL DEFAULT NULL,
`dateacquisition` VARCHAR(30) NULL DEFAULT NULL,
`codeusure` VARCHAR(30) NULL DEFAULT NULL,
`isbn` INT NULL DEFAULT NULL,
`id_editeur` VARCHAR(30) NULL DEFAULT NULL
)
;
-- -----------------------------------------------------
-- Table `bibliothèque`.`emprunt`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `bibliothèque`.`emprunt` (
`numeromatricule` VARCHAR(30) NULL DEFAULT NULL,
`coderayon` VARCHAR(30) NOT NULL,
`nombredelivres` INT NULL DEFAULT NULL,
`dateemprunt` VARCHAR(30) NULL DEFAULT NULL,
`dateretour` VARCHAR(30) NULL DEFAULT NULL
)
;
-- -----------------------------------------------------
-- Table `bibliothèque`.`rayon`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `bibliothèque`.`rayon` (
`idrayon` VARCHAR(30) NOT NULL,
`livre` INT NULL DEFAULT NULL,
`coderayon` VARCHAR(30) NULL DEFAULT NULL
)
;
Alter table auteur add PRIMARY KEY (`idauteur`);
alter table editeur add PRIMARY KEY (`idediteur`);
alter table fichiersabonnes add primary key (`numeromatricule`);
alter table motscles add PRIMARY KEY (`idmotscles`);
alter table livre add PRIMARY KEY (`isbn`);
alter table exemplairelivre add PRIMARY KEY (`coderayon`);
alter table emprunt add PRIMARY KEY (`coderayon`);
alter table rayon add PRIMARY KEY (`idrayon`);
alter table auteur add foreign key (`isbn`) References `bibliothèque`.`livre` (`isbn`);
alter table motscles add foreign key (`isbn`) References `bibliothèque`.`livre` (`isbn`);
Alter table livre add FOREIGN KEY (`id_auteur`) REFERENCES `bibliothèque`.`auteur` (`idauteur`);
alter table livre add FOREIGN KEY (`id_motscles`) REFERENCES `bibliothèque`.`motscles` (`idmotscles`);
alter table exemplairelivre add FOREIGN KEY (`isbn`) REFERENCES `bibliothèque`.`livre` (`isbn`);
alter table exemplairelivre add FOREIGN KEY (`id_editeur`) REFERENCES `bibliothèque`.`editeur` (`idediteur`);
alter table emprunt add FOREIGN KEY (`numeromatricule`) REFERENCES `bibliothèque`.`fichiersabonnes` (`numeromatricule`);
alter table emprunt add FOREIGN KEY (`coderayon`) REFERENCES `bibliothèque`.`exemplairelivre` (`coderayon`);
alter table rayon add FOREIGN KEY (`livre`) REFERENCES `bibliothèque`.`livre` (`isbn`);
alter table rayon add FOREIGN KEY (`coderayon`) REFERENCES `bibliothèque`.`exemplairelivre` (`coderayon`);