Commit 2e82200a authored by Gaetan Carabetta's avatar Gaetan Carabetta

Update SQL

parent 55c87664
CREATE TABLE Client(
idClient INT NOT NULL,
nom VARCHAR(30) NOT NULL,
prenom VARCHAR(30) NOT NULL,
ddn DATE NOT NULL,
adresse VARCHAR(100) NOT NULL,
numero NUMERIC(10) NOT NULL,
PRIMARY KEY(idClient)
);
CREATE TABLE Assistant(
idAssistant INT NOT NULL,
nom VARCHAR(30) NOT NULL,
prenom VARCHAR(30) NOT NULL,
ddn DATE NOT NULL,
adresse VARCHAR(100) NOT NULL,
numero NUMERIC(10) NOT NULL,
specialite VARCHAR(50),
PRIMARY KEY(idAssistant)
);
CREATE TABLE Veterinaire(
idVeterinaire INT NOT NULL,
nom VARCHAR(30) NOT NULL,
prenom VARCHAR(30) NOT NULL,
ddn DATE NOT NULL,
adresse VARCHAR(100) NOT NULL,
numero NUMERIC(10) NOT NULL,
specialite VARCHAR(50),
PRIMARY KEY(idVeterinaire)
);
CREATE TABLE ClasseEspece(
nomClasse VARCHAR(30) NOT NULL,
PRIMARY KEY(nomClasse)
);
CREATE TABLE Espece(
nomEspece VARCHAR(30) NOT NULL,
nomClasse VARCHAR(30) NOT NULL,
PRIMARY KEY(nomEspece),
FOREIGN KEY(nomClasse) REFERENCES ClasseEspece(nomClasse)
);
CREATE TABLE Animal(
idAnimal INT NOT NULL,
nom VARCHAR(30) NOT NULL,
poids REAL NOT NULL,
taille REAL NOT NULL,
naissance DATE,
idClient INT NOT NULL,
especeNom VARCHAR(30),
PRIMARY KEY(idAnimal),
FOREIGN KEY (idClient) REFERENCES Client(idClient),
FOREIGN KEY (especeNom) REFERENCES Espece(nomEspece)
);
CREATE TABLE Medicament(
nomMolec VARCHAR(30) NOT NULL,
description VARCHAR(200) NOT NULL,
PRIMARY KEY(nomMolec)
);
CREATE TABLE Traitement(
idTraitement INT NOT NULL,
idAnimal INT NOT NULL,
idVeterinaire INT NOT NULL,
PRIMARY KEY(idTraitement),
FOREIGN KEY(idVeterinaire) REFERENCES Veterinaire(idVeterinaire),
FOREIGN KEY(idAnimal) REFERENCES Animal(idAnimal)
);
CREATE TABLE Espece_Med(
nomEspece VARCHAR(30) NOT NULL,
nomMolec VARCHAR(30) NOT NULL,
FOREIGN KEY(nomEspece) REFERENCES Espece(nomEspece),
FOREIGN KEY(nomMolec) REFERENCES Medicament(nomMolec)
);
CREATE TABLE Posologie(
idAnimal INT NOT NULL REFERENCES Animal(idAnimal),
nomMolec VARCHAR(30) NOT NULL REFERENCES Medicament(nomMolec),
debut DATE NOT NULL,
duree INT NOT NULL,
nbJourna INT NOT NULL,
PRIMARY KEY(idAnimal, nomMolec, debut)
);
/*Methodes*/
/*à tester*/
/*
CREATE FUNCTION naissance (Naissance date)
returns date
as
begin
declare(@nais date)
set @nais =
case Naissance
when Naissance then Naissance
when NOT(Naissance) then NULL
end--case
return @nais
end;
CREATE FUNCTION espece_autoriser (Animal string, nomMolec string)
return (
SELECT CASE WHEN EXISTS (
SELECT *
FROM Espece_Med E JOIN Animal A
ON E.nomEspece = A.especeNom
AND A.idAnimal = Animal
WHERE E.nomMolec = nomMolec
)
THEN CAST(1 AS BIT)
ELSE CAST(0 AS BIT)
END -- CASE
)
END;
*/
/* Vues
vPersonne(Union(Projection(Client, nom, prenom, ddn, adresse, numero), Projection(Personnel, nom, prenom, ddn, adresse, numero)))
vPersonnel(Union(Projection(Assistant, nom, prenom, ddn, adresse, numero, specialite), Projection(Veterinaire, nom, prenom, ddn, adresse, numero, specialite)))
*/
/*à tester*/
/*
CREATE VIEW Personne (nom, prenom, ddn, adresse, numero) AS
SELECT C.nom, C.prenom, C.ddn, C.adresse, C.numero
FROM Client C
UNION ALL
(SELECT P.nom, P.prenom, P.ddn, P.adresse, P.numero
FROM Assistant A
UNION ALL
SELECT V.nom, V.prenom, V.ddn, V.adresse, V.numero, V.specialite
FROM Veterinaire V);
CREATE VIEW Personnel (nom, prenom, ddn, adresse, numero, specialite) AS
SELECT A.nom, A.prenom, A.ddn, A.adresse, A.numero, A.specialite
FROM Assistant A
UNION ALL
SELECT V.nom, V.prenom, V.ddn, V.adresse, V.numero, V.specialite
FROM Veterinaire V;
*/
/*
Les tables doivent être détruites
dans l'ordre inverse de leur création.
*/
DROP TABLE IF EXISTS Posologie;
DROP TABLE IF EXISTS Espece_Med;
DROP TABLE IF EXISTS Traitement;
DROP TABLE IF EXISTS Medicament;
DROP TABLE IF EXISTS Animal;
DROP TABLE IF EXISTS Espece;
DROP TABLE IF EXISTS ClasseEspece;
DROP TABLE IF EXISTS Veterinaire;
DROP TABLE IF EXISTS Assistant;
DROP TABLE IF EXISTS Client;
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment