0% found this document useful (0 votes)
14 views2 pages

Goiy De3

ád
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Goiy De3

ád
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

GÔÏI YÙ

BAØI SOÁ 1
PHẦN 1:
Câu 1:
select tennv
from nhanvien
where manv in(select manv
from tiepthi
group by manv
having count(tensp)=(select count(distinct tensp)
from cthoadon
where tiepthi.manv=manv)
)
Câu 2:
select tennv,sp.tensp, sum(soluong) as 'tong luong'
from nhanvien as nv, sanpham as sp, cthoadon as ct
where nv.manv=ct.manv and sp.tensp=ct.tensp
group by nv.manv,tennv,sp.tensp
having sum(soluong)>=all(select sum(soluong)
from cthoadon
where nv.manv=manv
group by tensp)
Câu 3:
select tennv, t.tensp
from nhanvien as nv, sanpham as sp, tiepthi as t
where (nv.manv=t.manv and sp.tensp=t.tensp)
and t.tensp not in( select tensp
from cthoadon
where nv.manv=manv)
PHẦN 2:
Câu 1:
create proc Sp_Min
as
select tensp
from sanpham
where dongia<=all(select dongia from sanpham)
Câu 2:
create proc TienTheoNgay @ngay datetime, @TongTien float OUTPUT
as
if not exists (select *
from cthoadon as ct, hoadon as hd
where (ct.sohd=hd.sohd and ct.manv=hd.manv)
and ngay=@ngay
)
set @TongTien=0
else
select @TongTien=sum(soluong*dongia)
from sanpham as sp, hoadon as hd, cthoadon as ct
where sp.tensp=ct.tensp and (ct.sohd=hd.sohd and ct.manv=hd.manv)
and ngay=@ngay
Câu 3:
create proc Spham_of_Nvien(@manvX char(10))
as
select tensp
from tiepthi
where manv=@manvX
PHẦN 3:
create trigger R1 create trigger R3
on tiepthi on tiepthi
for insert,update for insert, update
as as
if update(manv) or update(tensp) declare @sp char(20)
begin if update(tensp)
if (select count(*) begin
from tiepthi, inserted select @sp=tensp
where tiepthi.manv=inserted.manv)>5 from inserted
begin if @sp not in(select tensp from sanpham)
print 'khong them duoc ! moi nhan vien begin
duoc tiep thi toi da 5 sp' rollback tran
rollback transaction print 'Loi ve rang buoc tham chieu'
end end
end end
-- --
create trigger R2 create trigger R4
on hoadon on sanpham
for insert,update for insert,update
as as
declare @kv char(20) declare @gia float
if update(khuvuc) if update(dongia)
begin begin
select @kv=khuvuc select @gia=dongia
from inserted from inserted
if @kv not in('Q1','Q3','Q10') if @gia<=0
begin begin
rollback tran rollback tran
print 'Khu vuc khong hop le' print 'don gia phai >0'
end end
end end
--

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy