Université Badji Mokhtar //Faculté des Sciences de l’Ingénieur
Département d’Informatique
Correction d’Examen Bases de Données Avancées
Exercice 1 (12 Pts)
1. Modèle E/AE (2 Pts)
Spécialité
Enseignant 1, N
Code Etudiant
NSS
Nom Désignation Etudier 1, 1 Matricule
Prénom
Nom
Adresse
Groupe_TD Prénom
Tel
Fax 1, N Est_Dans
1, 1 Date_Naiss
Adresse
Email Num_GR_TD
1, 1 Tel
Num_Bureau
Email
Grade Représenter 0, 1
0, N 1, N 0, N 0, N
0, N
Gérer Enseigner
Année Est_Inscrit
1, 1 Année
1, N
Matière
1, N Examen
Code_Matière
Année Micro_Interrogation
Intitulé
Note Année
NB_Heures_Cours
0, N Note
NB_Heurs_TD
0, N
Epreuve
0, N Numéro
Coefficient 0, N
2. Requête en algèbre relationnelle (1 Pt)
∏ , é , [(𝐸𝑡𝑢𝑑𝑖𝑎𝑛𝑡 𝜎 é (𝑆𝑝é𝑐𝑖𝑙𝑎𝑖𝑡é))
_ , Code_Spécialité = Code
(𝜎 é (𝐼𝑛𝑠𝑐𝑟𝑖𝑝𝑡𝑖𝑜𝑛) 𝜎 é é (𝑀𝑎𝑡𝑖è𝑟𝑒))]
Matricule =Matricule Code_Matière =Code_Matière
3.
A) Requête en calcul de domaines (1 Pt)
{n, p | Enseignant(e, n, p, -, -, -, -, -, -) m1 m2 (Enseigne(e, m1, a)
Enseigne(e, m2, a) Matière(m1,’Bases de données’, -, -, -)
Matière(m2,’Algorithmiques’, -, -, -) (a=2009 a=2011))}
B) Requête en QBE (1 Pt)
Enseignant NSS Nom Prénom Adresse Tel Fax Email Num_Bureau Grade
e P. P.
Enseigne NSS Code_Matière Année Boîte condition
e M1 a a = 2009 OR a = 2011
e M2 a
Matière Code_Matière Intitulé NB_Heures_Cours NB_Heures_TD NSS_Responsable
M1 ‘Bases de données’
M2 ‘Algorithmiques’
4.
A) Requête en calcul de tuples (1 Pt)
{E.Nom, E.Prénom | Enseignant(E) S1 S2 S3 S4 M1 M2 ((Enseigne(S1)
Enseigne(S2) Enseigne(S3) Enseigne(S4) Matière(M1) Matière(M2)
(E.NSS = S1.NSS) (E.NSS = S2.NSS) (E.NSS = S3.NSS) (E.NSS = S4.NSS)
(S1.Code_Matière = M1.Code_Matière) (S2.Code_Matière = M2.Code_Matière)
(S3.Code_Matière = M1.Code_Matière) (S4.Code_Matière = M2.Code_Matière)
(M1.Intitulé = ’Bases de données’) (M2.Intitulé = ’Algorithmiques’)
(E.NSS = M1.NSS_Responsable) E.NSS = M2.NSS_Responsable) (S1.Année =
2010) (S2.Année = 2010) (S3.Année = 2011) (S4.Année = 2011))}
B) Requête en QUEL (1 Pt)
RANGE OF E, S1, S2, S3, S4, M1, M2 IS Enseignant, Enseigne, Enseigne,
Enseigne, Enseigne, Matière, Matière
RETREIVE E.Nom, E.Prénom
WHERE (E.NSS = S1.NSS) AND (E.NSS = S2.NSS) AND (E.NSS = S3.NSS) AND (E.NSS =
S4.NSS) AND (M1.Code_Matière = S1.Code_Matière) AND (S2.Code_Matière =
M2.Code_Matière) AND (M1.Code_Matière = S3.Code_Matière) AND (S4.Code_Matière
= M2.Code_Matière) AND (E.NSS = M1.NSS_Responsable) AND (E.NSS =
M2.NSS_Responsable) AND (M1.Intitulé = ’Bases de données’) AND (M2.Intitulé =
’Algorithmiques’) AND (S1.Année = 2010) AND (S2.Année = 2010) AND (S3.Année =
2011) AND (S4.Année = 2011);
5. Requête en SQL (1,5 Pts)
SELECT e.Nom, e.Prénom, e.Adresse
FROM Etudiant e, Spécialité s, Groupte_TD g
WHERE e.Code_Spécialité = s.Code AND g.Délégué = e.Matricule AND
s.Désignation=’Automatique’ AND ANY(SLECT e1.Note
FROM Examen e1
WHERE e.Matricule = e1.Matricule AND e1.Année
= 2011 AND e1.Code_Matière
NOT IN (SELECT DISTINCT e2.Code_Matière
FROM Enseigne e2, Enseignant e3
WHERE e2.NSS = e3.NSS AND e3.Grade <>
’Professeur’)
UNION
SLECT m.Note
FROM Micro_Interrogation m
WHERE e.Matricule = m.Matricule AND m.Année =
2011 AND m.Code_Matière
NOT IN (SELECT DISTINCT e2.Code_Matière
FROM Enseigne e2, Enseignant e3
WHERE e2.NSS = e3.NSS AND e3.Grade <>
’Professeur’)) > 12
6. Vue (1,5 Pt)
On crée tout d’abord la vue sélectionnant les notes et leurs coefficients des étudiants dont la spécialité
est informatique
CREATE VIEW Notes_Etudiants_Informatique (Matricule, Nom, Prénom, Code_Matière,
Année, Note, Coefficient)AS
SELECT e.Matricule, e.Nom, e.Prénom, e1.Code_Matière, e1.Année, e1.Note,
e2.Coeffecient
FROM Etudiant e, Examen e1, Spécialité s, Epreuve e2
WHERE e.Matricule = e1.Matricule AND s.Code = e.Code_Spécialité AND e1.Numéro =
e2.Numéro AND s.Désignation=’Informatique’
UNION
SELECT e.Matricule, e.Nom, e.Prénom, m.Code_Matière, m.Année, m.Note,
e1.Coeffecient
FROM Etudiant e, Micro_Interrogation m, Spécialité s, Epreuve e1
WHERE e.Matricule = m.Matricule AND s.Code = e.Code_Spécialité AND m.Numéro =
e1.Numéro AND s.Désignation=’Informatique’;
Puis la vue demandée
CREATE VIEW Résultat_Informatique(Matricule, Nom, Prénom, Code_Matière, Année,
Moyenne) AS
SELECT Matricule, Nom, Prénom, Code_Matière, Année, SUM(Note*Coefficient)/
SUM(Coefficient)
FROM Notes_Etudiants_Informatique
GROUP BY Matricule, Nom, Prénom, Code_Matière, Année;
7. Contrainte d’intégrité (1 Pt)
CREATE ASSERTION Contrôle_Nombre_Inscriptions
AFTER INSERT
CHECK NOT EXISTS(SELECT Code_Matière
FROM Inscription i, Etudiant e
WHERE e.Matricule = i.Matricule
GROUP BY i.Code_Matière
HAVING COUNT(*) > 3)
FOR EACH ROW OF Etudiant;
8. Déclencheur (1 Pt)
CREATE TRIGGER Suppression_Etudiant
BEFORE DELETE OF Etudiant
REFERENCING OLD_TABLE AS O
(DELETE FROM Inscription WHERE Matricule = O.Matricule;
DELETE FROM Examen WHERE Matricule = O.Matricule;
DELETE FROM Micro_Interrogation WHERE Matricule = O.Matricule;
UPDATE Groupe_TD SET Délégué = NULL WHERE Délégué = O.Matricule;
FOR EACH ROW);
Exercice 2
1. Schéma ODL de l’ODMG
module ODMGSystem_Commercial {
interface Client {//Interface abstraite pour implémentation dans une classe
attribute unsigned int CodeClient;
attribute set<string[14]> Tel;
attribute set<string[14]> Fax;
attribute set<string> Email;
attribute string Region;
relationship list<Commande> Passe inverse Commande::Passee_Par;
};
class Client_Public: Client (extent Clients_Publics key CodeClient) {/*classe
avec extension*/
attribute unsigned int CodeClient;
attribute set<string[14]> Tel;
attribute set<string[14]> Fax;
attribute set<string> Email;
attribute string Region;
attribute string Designation;
attribute set<struct(no, rue, ville, codepostal)> Adresse;
attribute set<struct(Numero, NomBanque)> Compte_Bancaire;
attribute string[20] Num_Reg_Commerce;
relationship list<Commande> Passe inverse Commande::Passee_Par;
};
class Client_Prive: Client (extent Clients_Prives key CodeClient) {/*classe avec
extension*/
attribute unsigned int CodeClient;
attribute set<string> Tel;
attribute set<string> Fax;
attribute set<string> Email;
attribute string Region;
attribute string Nom;
attribute string Prenom;
attribute struct Adresse (no, rue, ville, codepostal);
attribute struct Compte_Bancaire (Numero, NomBanque);
relationship list<Commande> Passe inverse Commande::Passee_Par;
};
class Produit (extent Produits key CodeProduit) {/*classe avec extension*/
attribute unsigned int CodeProduit;
attribute string Designation;
attribute string> TypeProduit;
attribute unsigned int Quantite_Stock;
attribute float Prix_Unitaire_HT;
relationship set<Ligne_Commande> Dans inverse Ligne_Commande::Concerne;
relationship list<Produit_Fourni> Est_Fourni inverse Produit_Fourni::En;
};
class Commande (extent Commandes key Num_Commande) {/*classe avec extension*/
attribute unsigned int Num_Commande;
attribute date Date;
relationship Client Passee_Par inverse Client::Passe;
relationship set<Ligne_Commande> Contient inverse Ligne_Commande::Appartient;
};
class Ligne_Commande (extent Lignes_Commandes key (Num_Commande, CodeProduit)){
/*classe avec extension*/
attribute unsigned int Num_Commande;
attribute unsigned int CodeProduit;
attribute unsigned int Quantite;
attribute float Prix_TTC;
relationship Commande Appartient inverse Commande::Contient;
relationship Produit Concerne inverse Produit::Dans;
};
class Fournisseur (extent Fournisseurs key CodeFournisseur) {/*classe avec
extension*/
attribute unsigned int CodeFournisseur;
attribute string Designation;
attribute set<struct (no, rue, ville, codepostal, pays)> Adresse;
attribute set<string[14]> Tel;
attribute set<string[14]> Fax;
attribute set<string> Email;
attribute string Region;
relationship list<Produit_Fourni> Fournit inverse Produit_Fourni::Fournit_Par;
};
class Produit_Fourni (extent Produits_Fournis key (CodeFournisseur, CodeProduit))
{/*classe avec extension*/
attribute unsigned int CodeFournisseur;
attribute unsigned int CodeProduit;
attribute unsigned int Quantite;
attribute date Date;
relationship Produit En inverse Produit::Est_Fourni;
relationship Fournisseur Fournit_Par inverse Fournisseur::Fournit;
};
};
2. Requête en OQL
SELECT p.CodeProduit, p.Designation, p.TypeProduit
FROM p IN Produits
WHERE p.CodeProduit IN (SELECT c.Passe.Contient.CodeProduit
FROM c IN Clients_Prives) AND
p.CodeProduit NOT IN (SELECT c.Passe.Contient.CodeProduit
FROM c IN Clients_Poublics);
3. Schéma SQL3
A) Création des Types
CREATE TYPE AS TADRESSE AS (no INT, rue VARCHAR(100), ville VARCHAR(50),
codepostal INT INSTANTIABLE NOT FINAL);
CREATE TYPE AS TADRESSSEP UNDER TADRESSE AS (pays VARCHAR(50) INSTANTIABLE
FINAL);
CREATE TYPE AS TCLIENT (CodeClient INT, Tel SET<VARCHAR(14)>, Fax
SET<VARCHAR(14)>, Email SET<VARCHAR(100)>, Region VARCHAR(100)INSTANTIABLE FINAL
REF IS CodeClient DERIVED);
CREATE TYPE AS TPRODUIT (CodeProduit INT, Designation VARCHAR(50), TypeProduit
VARCHAR(50), Quantite_Stock INT, Prix_Unitaire_HT FLOAT INSTANTIABLE FINAL REF IS
CodeProduit DERIVED);
CREATE TYPE AS TFOURNISSEUR (CodeFournisseur INT, Designation VARCHAR(50),
Adresse SET<TADRESSEP>, Tel SET<VARCHAR(14)>, Fax SET<VARCHAR(14)>, Email
SET<VARCHAR(100)>, Region VARCHAR(100)> INSTANTIABLE FINAL REF IS CodeFournisseur
DERIVED);
CREATE TYPE AS TCOMMANDE (Num_Commande INT, DateC Date, CodeClient REF(TCLIENT)
INSTANTIABLE FINAL REF IS Num_Commande DERIVED);
CREATE TYPE AS TLIGNE_COMMANDE(CodeProduit REF(TPRODUIT), Num_Commande
REF(TCOMMANDE) Quantite INT, Prix_TTC FLOAT);
CREATE TYPE AS TPRODUIT_FOURNI(CodeProduit REF(PRODUIT), CodeFournisseur
REF(TFOURNISSEUR) Quantite INT, DateF DATE);
B) Création des Tables
CREATE TABLE CLIENTS OF TCLIENT (PRIMARY KEY CodeClient)
CREATE TABLE CLIENTS_PUBLICS OF TCLIENT(Designation VARCHAR(50), Adresse
SET<TADRESSE>, Compte_Bancaire SET<ROW(Num_Compte INT, Nom_Banque VARCHAR(100))>,
Num_Reg_Commerce VARCHAR(20)) UNDER CLIENTS;
CREATE TABLE CLIENTS_PRIVES OF TCLIENT(Nom VARCHAR(20),Prenom VARCHAR(20),
Adresse TADRESSE, Compte_Bancaire ROW(Num_Compte INT, Nom_Banque VARCHAR(100)))
UNDER CLIENTS;
CREATE TABLE COMMANDES OF TCOMMANDE (PRIMARY KEY Num_Commande);
CREATE TABLE FOURNISSEURS OF TFOURNISSEUR (PRIMARY KEY CodeFournisseur);
CREATE TABLE PRODUITS_FOURNIS OF TPRODUIT_FOURNI;
CREATE TABLE LIGNES_COMMANDES OF TLIGNE_COMMANDE (PRIMARY KEY (Num_Commande,
CodeProduit));
CREATE TABLE PRODUITS_FOURNIS OF TLIGNE_COMMANDE (PRIMARY KEY
(CodeProduit,CodeFournisseur, DateF));
4. Requête en SQL3
SELECT p.CodeProduit, p.Designation, p.Prix_Unitaire_HT
FROM PRODUITS p
WHERE NOT EXISTS (SELECT CodeClient
FROM CLIENTS_PUBLICS
WHERE CodeClient NOT IN (
SELECT c.CodeClient
FROM COMMANDES c, LIGNES_COMMANDES l
WHERE c.Num_commande = l.Num_Commande
AND l.Code_Produit=p.Code_Produit))
AND NOT EXISTS (SELECT CodeFournisseur
FROM FOURNISSEURS f, PRODUITS_FOURNIS r
WHERE f.CodeFournisseur = r.CodeFournisseur AND
r.CodeProduit = p.CodeProduit and some(f.Adresse.pays) <>
’Almagne’));
Exercice 3
Planification Récupérable Evite l’annulation en cascade Stricte Sérialisable en conflit
S1 Oui Oui Oui Oui
S2 Oui Non Non Oui