Professional Documents
Culture Documents
EFM - SGBD 1 -
2014-2015 Solutions
//Auteur: CHAOULID
//Copyright: Exelib.net
//**D'autres solutions sont possibles**//
//Partie Pratique:
//A
//1
create database EFM_SGBD_1
go
use EFM_SGBD_1
http://slidepdf.com/reader/full/efm-sgbd-1-2014-2015-solutions 1/7
7/21/2019 EFM - SGBD 1 - 2014-2015 Solutions
Projet(Num_prj))
create table Travaille ( Matricule int foreign key
references Employe( Matricule) ,Num_tache int foreign
key references Tache(Num_tache),Nombre_heure
int,primary key( Matricule,Num_tache))
SELECT name, description
FROM fn_helpcollations()
http://slidepdf.com/reader/full/efm-sgbd-1-2014-2015-solutions 2/7
7/21/2019 EFM - SGBD 1 - 2014-2015 Solutions
//B
//1
select *
from
Employe
where Nom like 'El%[^a-f]'
order by DateNaissance
//2
select UPPER(Nom_tache) as "Nom de tâche"
from
Tache
where MONTH(date_fin)=MONTH(getdate())
//3
select COUNT(distinct Grade) as "Nombre de grades"
Employe
from
//4
select e.*
from
Employe e inner join Travaille t on
e. Matricule=t. Matricule inner join Tache ta on
t.Num_tache=ta.Num_tache inner join Projet p on
ta.Num_prj=p.Num_prj
where e.Num_serv!=p.Num_serv
//5
select * from
Tache
http://slidepdf.com/reader/full/efm-sgbd-1-2014-2015-solutions 3/7
7/21/2019 EFM - SGBD 1 - 2014-2015 Solutions
select *
from
Projet
where Num_prj in (select distinct Num_prj from
Tache
where DATEDIFF(DAY,date_debut,date_fin)<30) and Num_prj
in (select distinct Num_prj from
Tache where
DATEDIFF(DAY,date_debut,date_fin)>60)
//6
select ta.Num_prj,SUM(tr.Nombre_heure) as "Masse
horaire"
from
Travaille tr inner join Tache ta on
tr.Num_tache=ta.Num_tache
where YEAR(date_debut)=YEAR(getdate()) and
YEAR(date_fin)=YEAR(GETDATE())
group by Num_prj
//7
select e. Matricule,e.Nom
from
Employe e inner join Travaille tr on
e. Matricule=tr. Matricule inner join Tache ta on
tr.Num_tache=ta.Num_tache
group by e. Matricule,e.Nom ,e.Prenom
having COUNT( distinct ta.Num_prj)>=2
//8
select
*,DATEADD(year,Datediff(YEAR,DateNaissance,getdate()),D
ateNaissance) as "Dateanniversaire"
from
Employe
http://slidepdf.com/reader/full/efm-sgbd-1-2014-2015-solutions 4/7
7/21/2019 EFM - SGBD 1 - 2014-2015 Solutions
where
DATEADD(year,Datediff(YEAR,DateNaissance,getdate()),Dat
eNaissance) between
cast (DATEADD(DAY,-DATEPART(WEEKDAY,GETDATE())
+1+7,GETDATE()) as DATE) //-- la date du premier jour
de la semaine prochaine
and
cast (DATEADD(DAY,-DATEPART(WEEKDAY,GETDATE())
+1+7+6,GETDATE()) as DATE) //-- la date du dernier jour
de la semaine prochaine
//9
select *
from
Projet
where Num_prj in
(
select Num_prj
Tache
from
group by Num_prj
having count(distinct Num_tache)=
(
select MAX(PT.nombre_taches) //-- le max de nombre
de taches par projet
from
(
select Num_prj,count(distinct Num_tache)as
"nombre_taches" //-- table virtuelle
from
Tache
group by Num_prj
) as "PT"
http://slidepdf.com/reader/full/efm-sgbd-1-2014-2015-solutions 5/7
7/21/2019 EFM - SGBD 1 - 2014-2015 Solutions
)
)
//10
select
Num_prj,DATEDIFF(DAY,MIN(date_debut),
max(date_fin)) as
"Durée de réalisation"
from
Tache
group by Num_prj
//C
//1
update Employe
set Salaire=case
when Age>60 then Salaire+Salaire*5/100
//2
delete from
Tache
where Num_tache in (select Num_tache from
Tache where
GETDATE()>date_fin) and Num_tache not in (select
distinct Num_tache from
Travaille)
//D
//1
http://slidepdf.com/reader/full/efm-sgbd-1-2014-2015-solutions 6/7
7/21/2019 EFM - SGBD 1 - 2014-2015 Solutions
//2
create user Gestionnaire from
login CnxGestionnaire
create user ChefProjet from
login [ChefProjet-PC
\ChefProjet]
//3
grant insert,update,delete on Service to Gestionnaire
grant insert,update,delete on Projet to Gestionnaire
grant insert,update,delete on Tache to Gestionnaire
grant insert,update,delete on Travaille to Gestionnaire
//4
grant delete on Service to ChefProjet
grant delete on Projet to ChefProjet
grant delete on Tache to ChefProjet
http://slidepdf.com/reader/full/efm-sgbd-1-2014-2015-solutions 7/7