SQLSERVER数据库学习总结七(视图,索引)

--视图的主意点:不能和表的名称相同,如果某一列为函数,表达式,常量或者与来自多张表的列名相同,必须为列定义名称,不能在试图上创建索引

if exists(select 1 from sys.sysobjects where [name]='view_recordInfo')
    drop view view_recordInfo
go

create view view_recordInfo
as
    select 记录编号=r.Recordld,会员卡号=r.BeginTime,电脑编号=p.PCId
    from recordInfo r
    inner join PCInfo p
    on r.PCId=p.PCId
go

select * from view_recordInfo

--使用视图的优点:视点集中,简化操作,定制数据,合并分割数据,安全性

--索引:是一个单独的,物理的数据结构,是数据库的一张表中所包含的值得列表,其中注明了表的各个值所在的存储位置。
if exists(select 1 from sys.sysindexes where [name] = 'index_cardInfo_CardBalance')
    drop index cardInfo.index_cardInfo_CardBalance
go

create nonclustered index index_cardInfo_CardBalance
    on cardInfo(CardBalance)
    with
        fillfactor =40
go

--使用索引查询
select * from cardInfo
    with(index =index_cardInfo_CardBalance)
    where CardBalance between 10 and 100
go

--创建索引的原因主要是为了加大检索的速度

转载于:https://www.cnblogs.com/selfimprove/p/3587614.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值