Professional Documents
Culture Documents
Solution
A. Cration de la base de donnes
//Auteur: CHAOULID
//Copyright:Exelib.net
//**D'autres critures sont possibles**//
create database Gestion_comptes
go
use Gestion_comptes
create table Client(Num_cl int primary key
identity(1,1),Nom varchar(50), date_naissance
datetime,Tel varchar(16))
create table Compte(Num_cpt int primary key
identity(1,1), type varchar(50),date_creation
datetime,Num_cl int foreign key references
Client(Num_cl))
create table Operation(Num_opr int primary key
identity(1,1),libelle varchar(50),type char(1) default
'+',date_operation datetime,montant
decimal(10,2),Num_cpt int foreign key references
Compte(Num_cpt))
values('OP3','4/1/2016',300,2)
select * from Client
select * from Compte
select * from Operation
//Source : www.exelib.net
where o.type='+'
group by c.Num_cl
) c
left outer join
(
select c.Num_cl,SUM(o.montant) as "Somme_Dbiteurs"
from Operation o inner join Compte c on
o.Num_cpt=c.Num_cpt
where o.type='-'
group by c.Num_cl
) d
on c.Num_cl=d.Num_cl
) cs
// fin de la table virtuelle cs
inner join Client c on cs.Num_cl=c.Num_cl
where cs.Solde>10000
//5
select *
from Compte
where
Num_cpt
in
( // comptes quont enregistr une opration crditrice
ces 3 derniers jours.
select distinct Num_cpt
from Operation
where type='+'and
DATEDIFF(DAY,date_operation,GETDATE())<=3
)
and
Num_cpt
in
( // comptes quont enregistr une opration dbitrice
ces 3 derniers jours.
select distinct Num_cpt
from Operation
where type='-'and
DATEDIFF(DAY,date_operation,GETDATE())<=3
)
//5 une autre criture
select distinct c.*
from Compte c inner join Operation o on
c.Num_cpt=o.Num_cpt
where o.type='+'and
DATEDIFF(DAY,o.date_operation,GETDATE())<=3
intersect
select distinct c.*
from Compte c inner join Operation o on
c.Num_cpt=o.Num_cpt
where o.type='-'and
DATEDIFF(DAY,o.date_operation,GETDATE())<=3
2//
update Operation
set montant=case
when type='+' then montant*1.1
when type='-' then montant*0.9
else montant
end
where CAST(date_operation as DATE)=cast(GETDATE() as
DATE) and Num_cpt=100
D.Gestion de la scurit:
1//
create login Ahmed with
password='12345',default_database=Gestion_comptes
create login Salman with
password='12345',default_database=Gestion_comptes
2//
use Gestion_comptes
create user Ahmed for login Ahmed
create user Salman for login Salman
3//
exec sp_addrolemember 'r_agents','Ahmed'
exec sp_addrolemember 'r_agents','Salman'
4//
grant update,select on Object::Operation to
Ahmed,Salman
//Source : www.exelib.net