SQLServer视图
相当于创建一个“临时表”,其实是虚拟表,它是由真实的多个表组成的结果集。平时建议只对视图进行查询操作,增,删,修应该应用到真实的表结构。–视图对多个表的结果集合并。–视图:把多个表的结果集合并到一个视图中。–视图中的列必须具名。
·
视图
相当于创建一个“临时表”,其实是虚拟表,它是由真实的多个表组成的结果集
平时建议只对视图进行查询操作,增,删,修应该应用到真实的表结构。
视图没有参数。
视图:view
if exists (select * from sysobjects where id=object_id(N'v_studentInfo'))
drop view v_studentInfo
go
create view v_studentInfo
as
select * from StudentInfo;
go
查询视图
select * from v_studentInfo

–视图:把多个表的结果集合并到一个视图中
–视图中的列必须具名。
–视图对多个表的结果集合并。对结果集格式化。
if exists(select * from sysobjects where id=object_id(N'v_customerInfo'))
drop view v_customerInfo;
go
create view v_customerInfo
as
select C.CustomerId,C.CustomerName,C.Sex,
case C.Sex when 1 then '男' else '女' end as SexName,
case C.Sex when 1 then '男' when 0 then '女' else '未知' end as SexName1,
C.Age,C.Phone,
C.AddressId, A.ProvinceName + A.City + A.Area + A.DetailAddress as AddressDetail,
C.CreateUserId, U1.Account as CreateUserName,C.CreateTime,
C.LastUpdateUserId,U2.Account as LastUpdateUserName, C.LastUpdateTime,
C.Status,
case when C.Status=1 then '删除' when C.Status = 0 then '正常' else '未知' end as StatusName
from CustomerInfo as C
left join AddressInfo as A on C.AddressId = A.AddressId
left join UserInfo as U1 on C.CreateUserId = U1.UserId
left join UserInfo as U2 on C.LastUpdateUserId = U2.UserId
go
--查询视图
select * from v_customerInfo
where SexName='男'
更多推荐




所有评论(0)