1. Trang chủ
  2. » Công Nghệ Thông Tin

Code Hệ Quản Trị Cơ Sở Dữ Liệu

4 486 1

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 4
Dung lượng 14,03 KB

Nội dung

Create Table KH_BAC (Makh int, TenKh Nchar(30), Khuvuc Nvarchar(30) NOT NULL CHECK ( Khuvuc=Bac bo), PRIMARY KEY (Makh, Khuvuc) )Create Table KH_TRUNG (Makh int, TenKh Nchar(30), Khuvuc Nvarchar(30) NOT NULL CHECK ( Khuvuc=Trung bo), PRIMARY KEY (Makh, Khuvuc) )Create Table KH_NAM(Makh int, TenKh Nchar(30),Khuvuc Nvarchar(30) NOT NULL CHECK ( Khuvuc=Nam bo),PRIMARY KEY (Makh, Khuvuc)) create view danhsachasselect from dbo.KH_BACunion allselect from dbo.KH_TRUNGunion allselect from dbo.KH_NAMinsert into danhsachvalues (123,Nguyen Van A,Bac bo)insert into danhsachvalues (134,Sky,Bac bo)insert into danhsachvalues (345,Tran B,Bac bo)insert into danhsachvalues (111,Nguyen A,Trung bo)insert into danhsachvalues (245,Dao Anh,Trung bo)insert into danhsachvalues (342,Vo Van Kiet,Trung bo)insert into danhsachvalues (435,Nguyen Dao E,Nam bo)insert into danhsachvalues (349,Tran Hai,Nam bo)insert into danhsachvalues (342,Nguyen Duc,Nam bo) select from dbo.danhsach

module5 bai 11 module Create Table KH_BAC (Makh int, TenKh Nchar(30), Khuvuc Nvarchar(30) NOT NULL CHECK ( Khuvuc='Bac bo'), PRIMARY KEY (Makh, Khuvuc) ) Create Table KH_TRUNG (Makh int, TenKh Nchar(30), Khuvuc Nvarchar(30) NOT NULL CHECK ( Khuvuc='Trung bo'), PRIMARY KEY (Makh, Khuvuc) ) Create Table KH_NAM (Makh int, TenKh Nchar(30), Khuvuc Nvarchar(30) NOT NULL CHECK ( Khuvuc='Nam bo'), PRIMARY KEY (Makh, Khuvuc) ) create view danhsach as select *from dbo.KH_BAC union all select *from dbo.KH_TRUNG union all select *from dbo.KH_NAM insert values insert values insert values insert values insert values insert values insert values insert values insert values into danhsach (123,'Nguyen Van A','Bac bo') into danhsach (134,'Sky','Bac bo') into danhsach (345,'Tran B','Bac bo') into danhsach (111,'Nguyen A','Trung bo') into danhsach (245,'Dao Anh','Trung bo') into danhsach (342,'Vo Van Kiet','Trung bo') into danhsach (435,'Nguyen Dao E','Nam bo') into danhsach (349,'Tran Hai','Nam bo') into danhsach (342,'Nguyen Duc','Nam bo') select * from dbo.danhsach I batch bai1 declare @tongsoHD int select @tongsoHD= count([SalesOrderID]) from [Sales].[SalesOrderDetail] where [ProductID] =778 if @tongsoHD>500 print 'San Pham' +'778'+'co'+convert(char(5), @tongsoHD)+'tren 500 don hang' else print 'san pham '+ convert(char(5), @tongsoHD)+'co it don dat hang' go bai2 declare @makh int,@n int,@nam int set @makh=11527 set @nam=2008 select @n=count([SalesOrderID]) from [Sales].[SalesOrderHeader] where [CustomerID]=@makh and year([OrderDate])=@nam if(@n0) print 'khach hang '+convert(char(10),@makh)+'co '+convert(char(5),@n) +'hoa don nam 2008' else print'Khach hang khong co hoa don nao vao nam 2008' go bai3 use AdventureWorks2008; go select [SalesOrderID],sum([LineTotal]) as subtotal, discount = case when sum([LineTotal])

Ngày đăng: 06/12/2016, 11:57

TỪ KHÓA LIÊN QUAN

w