My SQL 2
Create table Lophoc
(
Malop char(5),
Tenlop nvarchar(50),
Makhoa char(5)
)
Create table Sinhvien
(
MaSv char(5),
Ten nvarchar(50),
Hodem nvarchar(50),
Ngaysinh datetime,
Noisinh nvarchar(50),
CMT char(15),
Malop char(5)
)
Create View vm_Lophoc As
Select C.masv,C.ten,C.hodem,C.ngaysinh,C.noisinh,C.cmt,c.malop
From Sinhvien C,Lophoc P
Where C.malop=P.malop
Select * from Vm_Lophoc
Create Procedure au_pro_lop2
As
Select C.masv,C.ten,C.hodem,C.ngaysinh,C.noisinh,C.cmt,C.malop,P.tenlop
From Sinhvien C,Lophoc P
Where C.malop=P.malop AND P.tenlop='quantrimang'
Exec au_pro_lophoc
VD:
Select P.Name,C.Name from Product P,Category C,ProductCategory PC
Where C.CategoryID=PC.CategoryID AND P.ProductID=PC.ProductID
Select * from Category,Product
Where CategoryID In ('1')
Select D.name As Departmentname,C.name As Categoryname,p.name As Productname
from Department D, Category C,Productcategory PC,Product P
Where D.DepartmentID=C.CategoryID AND C.CategoryID=PC.CategoryID
AND PC.ProductID=P.ProductID AND D.DepartmentID=1
View:
Create View vw_CategoryProduct As
Select C.Name CategoryName,P.Name ProductName,P.Description,P.Price
From Category C,Product P, ProductCategory PC
Where Pc.ProductID=P.ProductID AND PC.CategoryID=C.CategoryID
Procedure
Create Procedure au_pro_CategoryProduct
As
Select C.CategoryID,C.Name CategoryName,P.ProductID,P.Name ProductName,P.Description,P.Price
From Category C, Product P, ProductCategory PC
Where C.CategoryID=Pc.CategoryID AND P.ProductID=PC.ProductID
Exec au_pro_CategoryProduct
Bạn đang đọc truyện trên: Truyen247.Pro