đáp án SQL
111111 Create Table VATTU (MaVT nvarchar(5) primary key, TenVT nvarchar(20), Loai nvarchar(10), NuocSX nvarchar(20) )
Create Table NhaCungCAP (MaNCC nvarchar(5) primary key, TenNCC nvarchar(20), DiaChi nvarchar(40), DienThoai nvarchar(10), Constraint RB_NCC Unique(TenNCC),Check (DienThoai like ‘[0-9][0-9]) )
Create Table KhaNangCC (MaNCC nvarchar(5), MaVT nvarchar(5), SoLuongCo int(4), Gia Decimal(4,2) Primary Key (MaNCC,MaVT) )
Create Table PhieuDatHang (SoPhieu nvarchar(5) primary key, MaNCC nvarchar(5), MaVT nvarchar(5), SoLuong int(4), NgayDat datetime(4) check ( NgayDat>=getdate()) )
2222222 A.. Alter Table VatTu Add Constraint RB_VatTu Unique(TenVT),Check(Nuoc SX in(‘Viet Nam’,’Nhat’.’Han’))
BBBBBB. Alter Table PhieuDatHang Add Constraint RB_PDH Check(SoLuong>0)
33333333. Insert Into VatTu Values (‘VT01’,’LapTop’,’MayTinh’,’Nhat’) Insert Into VatTu Values (‘VT02’,’NokiaE71’,’DienThoai’,’Han’)
44444444. AAA. Update PhieuBanHang Set NgayDat=1/1/2005 where SoPhieu=’SP10’
BBB Update KhaNangCC Set Gia=20000000 From VatTu,NhaCungCap Where KhaNangCC,MaVT=VatTu.MaVT and KhaNangCC.MaNCC=NhaCungCap.MaNCC andTenVT=’Vaio BX’ and TenNCC=’Sony’
5555555 AAA. Select TenVT,count(MaVT) as SoPhieuXuat From tblPhieuDatHang as PDH,tblVatTu as VT Group by MaNCC,TenVT
BBB. Select TenVT,count(MaNCC) as SoPhieuXuat From tblPhieuDatHang as PDH, tblVatTu as VT where PDH.MaVT=VT.MaVT group by MaNCC,TenVT having count(MaNCC)>5
666666
Create View HangLon As Select * From PhieuDatHang Where SoLuong>50
7777777
Create Procedure vwKhaNangCC As Select * From KhaNangCC Where SoLuong>0
8888888.
Create Function LietKe@MaNCC nvarchar(5)) Return Table As Return (Select * From PhieuDatHang)
Bạn đang đọc truyện trên: AzTruyen.Top