Exercice 1 : Schéma : Servir(Bar, Bière)
Transcription
Exercice 1 : Schéma : Servir(Bar, Bière)
Exercice 1 : Schéma : Servir(Bar, Bière) Fréquenter(Buveur, Bar) Aimer(Buveur, Bière) 1. Donner les bars qui servent une bière appréciée par 'Dupont' S1 = RES (Aimer / Buveur = ‘Dupont’) S2 = NJN (S1, Servir) R1 = PJ (S2, Bar) SELECT Bar FROM Aimer A, Servir S WHERE S.Bière = A.bière AND Buveur ='Dupont'; 2. Donner les bières que servent les bars frequentés par ‘José’ S1 = RES (Fréquenter / Buveur = ‘José’) S2 = NJN (S1, Servir) R2 = PJ (S2, Bière) Select S.Bière From Servir S, Fréquenter F Where F.Bar = S.Bar and F.Buveur = ‘José’; 3. Donner les buveurs qui fréquentent au moins un bar où l'on sert la bière ‘Heineken’ qu'ils aiment S1 = RES (Servir / Biere = ‘Heineken’) S2= NJN (S1, Fréquenter) S3 = NJN (S2, Aimer) S4 = JN (S3, Servir / S3.Bière = Servir.Bière) R3 = PJ (S4, Buveur) Select F.Buveur From Servir S, Fréquenter F, Aimer A Where S.Bar = F.Bar And F.Buveur = A.Buveur And A.Bière = S.Bière And S.Bière = ‘Heineken’ ; Exercice 2 : Soit le schéma relationnel : EMP(Matr, NomE, Poste, DatEmb, Sup, Salaire, Commission, NumDept) DEPT(NumDept, NomDept, Lieu) PROJET(CodeP, NomP) PARTICIPATION(Matr, CodeP, Fonction) Questions : 1. Donner les matricules et noms des employés qui ont été embauchés avant le 1er janvier 1995. 2. Donner les noms des employés qui ont le poste de secrétaire. 3. Donner les noms des employés qui travaillent dans le département FINANCES. 4. Donner les noms des employés qui ne participent à aucun projet. UNIQUEMENT EN SQL 5. Donner les noms des départements qui ont des ingénieurs et/ou des secrétaires qui participent au projet ‘Automobile’. Solutions : 1. S1 = RES (EMP / DatEmb < ‘01/01/95’) R1 = PJ (S1, Matr, NomE) Select Matr, NomE From EMP Where DatEmb < ‘01/01/95’; 2. S1 = RES (EMP / Poste = ‘Secrétaire’) R2 = PJ (S1, NomE) Select NomE From EMP Where Poste = ‘Secrétaire’; 3. S1 = RES (DEPT / NomDept = ‘Finances’) S2 = NJN (S1, EMP) R3 = PJ (S2, NomE) Select E.NomE From EMP E, DEPT D Where E.NumDept = D.NumDept and NomDept = ‘FINANCES’; 4. Select E.NomE From EMP E Where E.Matr not in (Select P.Matr From PARTICIPATION P); 5. Donner les noms des départements qui ont des ingénieurs et/ou des secrétaires qui participent au projet ‘Automobile’. S1 = RES (EMP / Poste = ‘Secrétaire’ or Poste = ‘Ingénieur’) S2 = NJN (S1, DEPT) S3 = NJN (S2, PARTICIPATION) S4 = NJN (S3, PROJET) S5 = RES (S4 / NomP = ‘Automobile’) R5 = PJ (S5, NomDept) Select D.NomDept From EMP P, DEPT D, PROJET Pr, PARTICIPATION Pa Where E.NumDept = D.NumDept And E.Matr = Pa.Matr And Pa.CodeP = Pr.CodeP And Pr.NomP = ‘Automobile’ And ( E.Poste = ‘Secretaire’ or E.Poste = ‘Ingénieur’) ; Exercice 3 : Soit la base de données relationnelle de schéma suivant : SALLE (Nom,Horaire,Titre) FILM (Titre, Realisateur, Acteur) PRODUIT (Producteur,Titre) 1. S1 = RES (SALLE / Titre = ‘Le Seigneur des anneaux’) R1 = PJ (S1, Nom, Horaire) Select Nom, Horaire From SALLE Where Titre = ‘Le Seigneur des anneaux’ ; 2. S1 = RES (FILM / Acteur = ‘Tom Hanks’) S2 = NJN (S1, SALLE) R2 = PJ (S2, Nom) Select Nom From FILM F, SALLE S Where F.Titre = S:Titre And F.Acteur = ‘Tom Hanks’; 3. S1 = RES (FILM / Acteur = ‘Elisabeth Hurley’) S2 = NJN (S1, SALLE) S3 = RES (S2 / Horaire > 16) R3 = PJ (S3, Nom) Select Nom From FILM F, SALLE S Where F.Titre = S.Titre And F.Acteur = ‘Elisabeth Hurley’ And S.Horaire > 16; Exercice 4: Soit le schéma relationnel suivant : MATERIEL (N°Matériel, désignation, marque, description, prix, N°Fournisseur) FOURNISSEUR (N°Fournisseur, nom, adresse, code_postal, ville, telephone) CLIENT (N°Client, nom, adresse, code_postal, ville) COMMANDE (N°Commande, N°Client, date) DESCRIPTIFCOMMANDE (N°Commande, N°Matériel, Quantite) 1. R1 = PJ (FOURNISSEUR, nom) Select nom From FOURNISSEUR ; 2. S1 = RES (CLIENT / ville = ‘Nancy’) R2 = PJ (S1, nom, adresse) Select nom, adresse From CLIENT Where ville = ‘Nancy’ ; 3. S1 = RES (CLIENT / ville = ‘Paris’) S2 = NJN (S1, COMMANDE) S3 = RES (S2 / date = 2002) R3 = PJ (S3, nom) Select nom From CLIENT C1, COMMANDE C2 Where C1.N°Client = C2.N°Client And C1.ville = ‘Paris’ And C2.date = 2002 ; 4. S1 = RES (CLIENT / N°Client = 1) S2 = NJN (S1, COMMANDE) S3 = RES (S2 / date = 2001 ou date = 2002) S4 = NJN (S3, DESCRIPTIFCOMMANDE) S5 = NJN (S4, MATERIEL) R4 = PJ (S4, designation, prix) Select M.designation, M.prix From MATERIEL M, CLIENT C1, COMMANDE C2, DESCRIPTIFCOMMANDE D Where C1.N°Client = C2.N°Client And C2.N°Commande = D:N°Commande And D.N°Materiel = M.N°Materiel And C1.N°Client = 1 And (C2.date = 2001 ou C2.date = 2002) ; 5. S1 = RES (CLIENT / ville = ‘Marseille’) S2 = NJN (S1, COMMANDE) S3 = NJN (S2, DESCRIPTIFCOMMANDE) S4 = NJN (S3, MATERIEL) S5 = NJN (S4, FOURNISSEUR) S6 = RES (S5 / FOURNISSEUR.ville = ‘Paris’) R5 = PJ (S6, N°Materiel) Select M.N°Materiel From MATERIEL M, FOURNISSEUR F, CLIENT C1, COMMANDE C2, DESCRIPTIFCOMMANDE D Where C1.N°Client = C2.N°Client And C2.N°Commande = D.N°Commande And D.N°Materiel = M.N°Materiel And M.N°Fournisseur = F.N°Fournisseur And C1.ville = ‘Marseille’ and F.ville = ‘Paris’ ;