Page 772 - IT2
P. 772
Dossier 2 :
1. Select top 3 * From Candidats Order By nombreVoix desc , dateNaissance
2. Select * From Electeurs E Where (Select count(idCandidat) From Votes V Where V.idElecteur =
E.idElecteur) = 1
3. Create function Liste (@idCandidat int)
Returns Table
As
Return ( Select * from Electeurs E inner join Votes V on E.idElecteur = V.idElecteur Where idCandidat =
@idCandidat)
4. Create procedure psVoter @idElect int , @idCandidat1 int = NULL , @idCandidat2 int = NULL ,
@idCandidat3 int = NULL
As
If @idCandidat1 IS NOT NULL
Insert into Votes VALUES (@idElecteur, @idCandidat1)
If @idCandidat2 IS NOT NULL
Insert into Votes VALUES (@idElecteur, @idCandidat2)
If @idCandidat3 IS NOT NULL
Insert into Votes VALUES (@idElecteur, @idCandidat3)
If @idCandidat1 IS NULL AND @idCandidat2 IS NULL AND @idCandidat3 IS NULL
RAISERROR (‘Il faut choisir au moins un candidat’ , 16 , 1)
5. Create Trigger t1 ON Votes
After Insert
As
Update Candidats set nombreVoix = nombreVoix + 1
From Inserted Where Candidats.idCandidat = Inserted.idCandidat
Filière Epreuve Session 3/5
DI Théorique FF (Elément de correction) Juillet 2015
www.itlearning-settat.com
Email: admission@itlearning-settat.com
Tél.:0661077812

