bibliotheque
This commit is contained in:
188
bibliotheque/bibliotheque.sql
Normal file
188
bibliotheque/bibliotheque.sql
Normal file
@@ -0,0 +1,188 @@
|
||||
-- Lookup tables
|
||||
drop table if exists langues;
|
||||
drop table if exists pays;
|
||||
drop table if exists statuts;
|
||||
|
||||
drop table if exists auteurs;
|
||||
drop table if exists editeurs;
|
||||
drop table if exists series;
|
||||
drop table if exists relations;
|
||||
drop table if exists oeuvres;
|
||||
drop table if exists participe;
|
||||
drop table if exists editions;
|
||||
drop table if exists exemplaires;
|
||||
drop table if exists genres;
|
||||
drop table if exists collections;
|
||||
|
||||
drop table if exists adherents;
|
||||
drop table if exists adresses;
|
||||
drop table if exists adherent_adresse;
|
||||
|
||||
drop table if exists commande_historique;
|
||||
drop table if exists commande_ligne;
|
||||
drop table if exists commande;
|
||||
drop table if exists commande_statut;
|
||||
drop table if exists livraison_methode;
|
||||
|
||||
--
|
||||
PRAGMA integrity_check;
|
||||
PRAGMA foreign_key_check;
|
||||
|
||||
CREATE TABLE langues (
|
||||
langue_id INTEGER,
|
||||
langue_code VARCHAR(5) PRIMARY KEY,
|
||||
langue TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE auteurs (
|
||||
auteur_id INTEGER PRIMARY KEY,
|
||||
Nom TEXT DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE editeurs (
|
||||
editeur_id INTEGER PRIMARY KEY,
|
||||
Nom TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE series (
|
||||
serie_id INTEGER PRIMARY KEY,
|
||||
Nom TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE oeuvres (
|
||||
oeuvre_id INTEGER PRIMARY KEY,
|
||||
titre TEXT,
|
||||
isbn13 TEXT,
|
||||
langue_code VARCHAR(5) REFERENCES langues (langue_code),
|
||||
num_pages INTEGER,
|
||||
publication_date DATE,
|
||||
editeur_id INTEGER,
|
||||
genre_id INTEGER,
|
||||
serie_id INTEGER,
|
||||
CONSTRAINT fk_oeuvre_editeur FOREIGN KEY (editeur_id) REFERENCES editeurs (editeur_id),
|
||||
CONSTRAINT fk_oeuvre_genre FOREIGN KEY (genre_id) REFERENCES genres (genre_id),
|
||||
CONSTRAINT fk_oeuvre_serie FOREIGN KEY (serie_id) REFERENCES series (serie_id)
|
||||
);
|
||||
|
||||
CREATE TABLE editions (
|
||||
edition_id INTEGER PRIMARY KEY,
|
||||
oeuvre_id INTEGER REFERENCES oeuvres (oeuvre_id),
|
||||
editeur_id INTEGER REFERENCES editeurs (editeur_id),
|
||||
isbn13 TEXT,
|
||||
langue_code VARCHAR(5) REFERENCES langues (langue_code),
|
||||
publication_date DATE,
|
||||
num_pages INTEGER,
|
||||
num_catalogue INTEGER
|
||||
informations TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE exemplaires (
|
||||
exemplaire_id INTEGER PRIMARY KEY,
|
||||
edition_id INTEGER REFERENCES editions (edition_id),
|
||||
date_achat DATE,
|
||||
prix_achat NUMERIC,
|
||||
etat TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE relations (
|
||||
reference_id INTEGER REFERENCES oeuvres (oeuvre_id),
|
||||
oeuvre_id INTEGER REFERENCES oeuvres (oeuvre_id),
|
||||
[type] TEXT,
|
||||
CONSTRAINT pk_relation PRIMARY KEY (reference_id, oeuvre_id)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE genres (
|
||||
genre_id INTEGER PRIMARY KEY,
|
||||
genre TEXT
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE participe (
|
||||
oeuvre_id INTEGER NOT NULL REFERENCES oeuvres (oeuvre_id),
|
||||
auteur_id INTEGER NOT NULL REFERENCES auteurs (auteur_id),
|
||||
fonction TEXT,
|
||||
alias TEXT
|
||||
CONSTRAINT pk_oeuvreauteur PRIMARY KEY (oeuvre_id, auteur_id)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE incorpore (
|
||||
oeuvre_id INTEGER NOT NULL REFERENCES oeuvres (oeuvre_id),
|
||||
edition_id INTEGER NOT NULL REFERENCES editions (edition_id)
|
||||
)
|
||||
|
||||
CREATE TABLE statuts (
|
||||
statut_id INTEGER PRIMARY KEY,
|
||||
statut TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE pays (
|
||||
pays_id INTEGER PRIMARY KEY,
|
||||
pays_name TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE adresses (
|
||||
adresse_id INTEGER PRIMARY KEY,
|
||||
numero TEXT,
|
||||
voie TEXT,
|
||||
ville TEXT,
|
||||
pays_id INTEGER REFERENCES pays (pays_id)
|
||||
);
|
||||
|
||||
CREATE TABLE adherents (
|
||||
adherent_id INTEGER PRIMARY KEY,
|
||||
prenom TEXT NOT NULL,
|
||||
nom TEXT NOT NULL,
|
||||
email TEXT,
|
||||
naissance CHAR(10),
|
||||
statut_id INTEGER,
|
||||
CONSTRAINT fk_a_statut FOREIGN KEY (statut_id) REFERENCES statuts (statut_id)
|
||||
);
|
||||
|
||||
CREATE TABLE adherent_adresse (
|
||||
adherent_id INTEGER NOT NULL,
|
||||
adresse_id INTEGER NOT NULL,
|
||||
statut_id INTEGER,
|
||||
CONSTRAINT pk_adherent_adresse PRIMARY KEY (adherent_id, adresse_id),
|
||||
CONSTRAINT fk_aa_adherent FOREIGN KEY (adherent_id) REFERENCES adherents (adherent_id),
|
||||
CONSTRAINT fk_aa_adresse FOREIGN KEY (adresse_id) REFERENCES adresses (adresse_id),
|
||||
CONSTRAINT fk_aa_statut FOREIGN KEY (statut_id) REFERENCES statuts (statut_id)
|
||||
);
|
||||
|
||||
CREATE TABLE livraison_methode (
|
||||
methode_id INTEGER PRIMARY KEY,
|
||||
methode_name TEXT,
|
||||
cout NUMERIC
|
||||
);
|
||||
|
||||
CREATE TABLE commande (
|
||||
commande_id INTEGER PRIMARY KEY,
|
||||
commande_date DATETIME,
|
||||
date_echeance DATE,
|
||||
adherent_id INTEGER REFERENCES adherents (adherent_id),
|
||||
livraison_methode_id INTEGER REFERENCES livraison_methode (methode_id),
|
||||
dest_adresse_id INTEGER REFERENCES adresses (adresse_id)
|
||||
);
|
||||
|
||||
CREATE TABLE commande_statut (
|
||||
statut_id INTEGER PRIMARY KEY,
|
||||
statut_value TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE commande_ligne (
|
||||
ligne_id INTEGER PRIMARY KEY,
|
||||
commande_id INTEGER REFERENCES commande (commande_id),
|
||||
exemplaire_id INTEGER REFERENCES exemplaires (exemplaire_id),
|
||||
cout NUMERIC,
|
||||
date_retour DATETIME
|
||||
);
|
||||
|
||||
CREATE TABLE commande_historique (
|
||||
historique_id INTEGER PRIMARY KEY,
|
||||
commande_id INTEGER REFERENCES commande (commande_id),
|
||||
statut_id INTEGER REFERENCES commande_statut (statut_id),
|
||||
statut_date DATETIME
|
||||
);
|
||||
|
||||
-- *****
|
||||
Reference in New Issue
Block a user