Vous êtes sur la page 1sur 7

1) La procédure permettant de lister les stagiaires d'une filière donnée

CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`(nf int)


begin
select * from stagiaire where NFiliere= nf;
end$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `p11`(nf varchar(60))


begin
select s.*
from stagiaire s, filiere f
where s.NFiliere=f.NFiliere
and f.intituleFil = nf;
end$$

2) La procédure permettant d'afficher les stagiaires ayant l'âge dans la tranche précisée par
l'utilisateur.

CREATE DEFINER=`root`@`localhost` PROCEDURE `p2`(v1 int, v2 int)


begin
select `NStagiaire`, `Nom`, `Prenom`, `dateNaiss`, `dateInsc`,
`Adresse`, `tel`,year(curDate())-year(dateNaiss) as 'age'

from stagiaire
where year(curDate())-year(dateNaiss) between v1 and v2;
end$$

3) Augmenter d'un point les notes des stagiaires dans le module –C++-

CREATE DEFINER=`root`@`localhost` PROCEDURE `p3`()


begin
update Notation
set note = note +1
where NModule=(select NModule from module where intituleMod like
'CSS');
end$$
4) La liste des stagiaires dont le nom commence par une lettre spécifiée par l'utilisateur

CREATE DEFINER=`root`@`localhost` PROCEDURE `p4`(x char)


begin
select * from stagiaire
where left(prenom,1) =x;
end$$

5) La procédure permettant de lister les notes d'un stagiaire donné

CREATE DEFINER=`root`@`localhost` PROCEDURE `p5`( ns int)


begin
select * from notation
where NStagiaire =ns;
end$$

6) Le bulletin de notes d'un stagiaire donné.

CREATE DEFINER=`root`@`localhost` PROCEDURE `qst6`(ns int)


begin
/* tester si le stagiaire existe*/
select count(*) into @nbrs
from stagiaire where NStagiaire=ns;
if @nbrs=0 then
select concat('Le stagiaire num ',ns ,' N est pas inscrit dans la BD');
else
begin
/* tester si le stagiaire a passé des exam*/

select count(*) into @nbr


from notation
where NStagiaire=ns;
if @nbr=0 then
select ' ce stagiaire a raté tous ses examens';
else
begin
/*Lister les notes du stagiaire*/
select m.NModule , m.intituleMod,n.note
from module m ,notation n
where m.NModule=n.NModule
and n.NStagiaire=ns;

/* calculer la moyenne */
Select avg(note)
from notation where NStagiaire=ns;
/*decision*/
Select avg(note) into @m
from notation where NStagiaire=ns;
if @m<10 then
select 'redoublant' as 'decision';
else
select 'reussi' as 'decision';
end if;
end;
end if;
end;
end if;
end$$

7) Liste des stagiaires inscrits entre deux dates.

CREATE DEFINER=`root`@`localhost` PROCEDURE `ex7`(d1 date , d2


date)
begin

select * from stagiaire


where dateInsc between d1 and d2;
/* where dateInsc >d1 and dateInsc <d2 */

end$$

8) Liste des stagiaires non notés pour le module -JS-

CREATE DEFINER=`root`@`localhost` PROCEDURE `ex8`(nf int)


begin

select count(*)
into @nbr
from stagiaire
where NFiliere = nf;

if @nbr=0 then
begin
select concat (' aucun stagiaire n est inscrit
dans la filiere ,' , nf );
delete from filiere where NFiliere = nf;
End;
else
select concat (@NBR , ' stagiaires sont
inscrits dans la filiere ,' , nf );
eND IF;

end$$

9) Procédure qui vérifie si une filière dont le code est donné en paramètre, possède des
stagiaires, affiche un message, sinon supprimer cette filière .

delimiter $$
create procedure ex9(NumF int)
begin
/*Verifier si la filiere existe */
if exists( select * from filiere where NFiliere =numF) then
begin
/*Verifier si la filiere contient des stagiaires */
if exists( select * from stagiaire where NFiliere =numF) then
Select concat( 'La filiere num : ' , numF , ' Contient des stagiaires, On ne peut
pas la supprimer') as 'Remarque';
else
Begin
Select concat( 'Aucun stagiaire n est inscrit dans La filiere num : ' , numF , ' , Elle
sera supprimée') as 'Resultat';
delete from filiere where NFiliere =NumF;
End;
end if;
end;
else
Select concat( ' La filiere num : ' , numF , ' , n existe pas ') as 'Resultat';
end if;end$$

10) Créer une table archive_filière ayant la même structure que filière.
Procédure qui vérifie si une filière dont le code est donné en paramètre, possède des
stagiaires, affiche un message,
Sinon
On archive cette filière dans la table archive_filière
Supprimer cette filière
Afficher un message de confirmation

delimiter $$
create procedure ex10(numF int)
begin

/*Verifier si la filiere existe */


if exists( select * from filiere where NFiliere =numF) then
begin
/*Verifier si la filiere contient des stagiaires */
if exists( select * from stagiaire where NFiliere =numF) then
Select concat( 'La filiere num : ' , numF , ' Contient des stagiaires, On ne
peut pas la supprimer') as 'Remarque';
else
Begin
Select concat( 'Aucun stagiaire n est inscrit dans La filiere num : ' , numF , ' ,
Elle sera supprimée') as 'Resultat';
/* archiver la filiere avant de la supprime */
insert into Archive_filiere select * from filiere where NFiliere =NumF;
delete from filiere where NFiliere =NumF;
End;
end if;
end;
else
Select concat( ' La filiere num : ' , numF , ' , n existe pas ') as 'Resultat';
end if;
end$$

11) Afficher les informations des stagiaires qui ont plus de deux notes.(ont passé plus de 2
exams)
delimiter $$
create procedure ex11()
begin

select s.NStagiaire, s.Nom, s.Prenom, s.dateNaiss, count(n.note) as ‘Nombre de notes’


from stagiaire s, notation n
where s.NStagiaire=n.NStagiaire
group by s.NStagiaire, s.Nom, s.Prenom, s.dateNaiss
having count(n.note)>2 ;

end$$

12) Pour retourner le nombre des stagiaires inscrits dans une filière donnée.

nbrs
Nf

delimiter $$
create procedure ex12(in nf int, out nbrs int)
begin
select count(s.NStagiaire)
into nbrs
from stagiaire s
where s.NFiliere =nf;
end$$
Set @x=0 ;
Exec ex12(3,@x)
SELECT CONCAT( @x , ' stagiaires sont inscrits dans la filiere', 3 )

13) Pour retourner l’intitulé, capacité, nombre d’année d’une filière donnée.
Intitulé filiere
nf Capacité
Nbr Année

delimiter $$
create procedure ex13(in nf int, out t varchar(60) ,out cap int , out an int)
begin

select intituleFil , capacite , NbrAnnee


into t,cap, an
from filiere
where NFiliere =nf;
end$$
Set @t='' ;
Set @cap='' ;
Set @an='' ;
Set @code=3 ;
call ex13(@code, @t,@cap,@an);
SELECT CONCAT( @code,'\t', @t,'\t',@cap,'\t',@an )
as 'code intitulé capacita NbrAn'

14) Qui ajoute une notation Qui ajoute une notation


Si le stagiaire n’existe pas : elle affiche un message,
Sinon ,Si le module n’existe pas, elle va le créer avec intitulé : Nouveau module, Masse
horaire:0 ;
sinon On peut créer la note

Set @pk=0;
Select max(NModule) into @pkfrom module
Set @pk=@pk+1;
Insert into module values(@PK , ‘Nouveau module’, 0)
Insert into notation(@numéroNot , @NStagiaire, @NModule, @note )

delimiter $$
create procedure ex14(NNota int, NSta int, NMo int, nt int)
begin
/* Verifier si le stagiaire existe */
if exists ( select * from stagaire where NStagiaire= NSta) then
/* tester si le module numéro =NMo existe */
if exists (select * from module where Nmodule=NMo) then
insert into notation values(NNota , NSta , NMo , nt );
select 'la note a été créée avec succes';
else
/* Il faut créer le module */
set @pk =0;
select max(NModule) into @pk
from Module;

set @pk=@pk+1;
insert into module values(@pk, 'New Module' ,0);
select 'le module a été créé avec succes';
insert into notation values(NNota , NSta , @pk, nt );
select 'la note a été créée avec succes';
end if;

else
select ' ce stagiaire n existe pas ' as 'remarque';
end if;
end$$

Vous aimerez peut-être aussi