SQLSERVER数据库学习总结七(视图,索引)
2014-03-08 10:40
274 查看
--视图的主意点:不能和表的名称相同,如果某一列为函数,表达式,常量或者与来自多张表的列名相同,必须为列定义名称,不能在试图上创建索引
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
--创建索引的原因主要是为了加大检索的速度
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
--创建索引的原因主要是为了加大检索的速度
相关文章推荐
- MySQL主从监控脚本
- Sql Server 取出表结构
- 数据库的增删改查
- oracle使用细节_nvl(sum(MM),0)
- mysql减肥法
- java操作redis
- sql数据库导入导出
- 精简Oracle客户端+PLSQL Deve…
- 浅谈oracle 存储后台进程和用户进程的debug trace log(上)
- MySQLdump增量备份、完全备份与恢复
- SQL SERVER 时间日期处理函数
- Mysql Workbench 学习
- Oracle数据导入导出imp/exp sp2-0734:未知的命令开头'imp 忽略了剩余行默认分类 解决办法
- oracle四个重要的后台进程(DBWR / LGWR / ARCH / CKPT)
- SQL的四种连接-左外连接、右外连接、内连接、全连接
- 浅谈Oracle Freelist
- Foxpro数据库连接错误解决方法--【VFP DBF文件不是一个有效的路径。 确定路径名称拼写是否正确,以及是否连接到文件存放的服务器】
- 总结PLSQL的快捷键以及使用技巧
- redis存储对象的方法
- redis.conf配置说明