First commit

This commit is contained in:
Yorick Barbanneau 2018-10-12 23:06:04 +02:00
commit 5c269302ed
59 changed files with 5613 additions and 0 deletions

View file

@ -0,0 +1,43 @@
CREATE SCHEMA Bibliotheque;
SET search_path TO Bibliotheque, public;
CREATE TYPE Bibliotheque.Sexe AS ENUM ('F', 'M');
CREATE TYPE Bibliotheque.Etat AS ENUM ('Neuf', 'Bon', 'Use');
CREATE TABLE Bibliotheque.Lecteur (
num_lecteur serial NOT NULL,
nom text NOT NULL,
sexe Bibliotheque.Sexe NOT NULL,
-- age devient date de naissance
naissance date NOT NULL,
ville text NOT NULL,
-- clefs candidates
PRIMARY KEY (num_lecteur)
);
CREATE TABLE Bibliotheque.Livre (
isbn integer NOT NULL,
titre text NOT NULL,
auteur text NOT NULL,
editeur text NOT NULL,
annee interval YEAR NOT NULL,
-- clefs candidates
PRIMARY KEY (isbn)
);
CREATE TABLE Bibliotheque.Exemplaire (
num_exemplaire serial NOT NULL,
isbn integer NOT NULL,
date_achat date NOT NULL,
etat Bibliotheque.Etat NOT NULL,
-- clefs candidates
PRIMARY KEY (num_exemplaire),
-- Clefs étrangères
FOREIGN KEY (isbn) REFERENCES Bibliotheque.Livre(isbn)
);
CREATE TABLE Bibliotheque.Emprunt (
num_exemplaire serial NOT NULL,
num_lecteur serial NOT NULL,
date_emprunt date NOT NULL,
-- clefs candidates
PRIMARY KEY (num_exemplaire, num_lecteur),
-- Clefs étrangères
FOREIGN KEY (num_exemplaire) REFERENCES Bibliotheque.Exemplaire(num_exemplaire),
FOREIGN KEY (num_lecteur) REFERENCES Bibliotheque.Lecteur(num_lecteur)
);

Binary file not shown.

View file

@ -0,0 +1,41 @@
-- schema de Base de données pour la gestion d'une compagnie aérienne.
CREATE SCHEMA aerocremi;
SET search_path TO aerocremi, public;
CREATE TABLE aerocremi.avion(
-- Je pars du principe que le numéro de série est donné par le fabricant
-- de l'avion et qu'il ne contient que des chiffres. Il ne peut donc pas
-- être du type serial.
num_serie integer NOT NULL,
type text NOT NULL,
capacite integer NOT NULL,
PRIMARY KEY (num_serie)
);
CREATE TABLE aerocremi.pilote(
matricule serial NOT NULL,
nom text NOT_NULL,
anciennete date,
PRIMARY KEY (matricule)
);
CREATE TABLE aerocremi.vol(
num_vol text NOT NULL,
-- Je part du principe qu'il faut gérer les times zones sur les horaires
-- de vol (logique pour une compagnie aérienne)
-- https://www.postgresql.org/docs/current/static/datatype-datetime.html
heure_depart time with time zone NOT NULL,
heure_arrivee time with time zone NOT NULL,
PRIMARY_KEY (num_vol)
);
CREATE TABLE aerocremi.planning(
num_planning serial NOT NULL,
num_vol text NOT NULL,
matricule integer NOT NULL,
date_vol date NOT NULL
PRIMARY KEY (num_planning),
FOREIGN KEY num_vol REFERENCES aerocremi.vol(num_vol),
FOREIGN KEY num_avion REFERENCES aerocremi.avion(num_serie),
FOREIGN KEY matricule REFERENCES aecrocremi.pilote(matricule)
);

Binary file not shown.