18-SQLServer中给视图创建索引
一、注意点
1、索引视图所引用的基表必须在同一个数据库中,不是用union all引用多个数据库的表;
2、创建索引视图时要加上with schemabinding;
3、创建索引视图时要指定表所属的架构;
4、在创建索引视图的select语句时,不能使用*,必须指定具体的列名;
5、只能为索引视图创建唯一聚集索引;
6、索引视图中的select包含一个或多个 UNION、INTERSECT 或 EXCEPT 运算符时,不能创建索引(创建视图时不报错,创建索引的时候会报错);
二、操作步骤
--1.创建索引视图
create view v_customer_sch_index with schemabinding
as
select Col1,Col2 from dbo.customer
go
--2.创建普通视图
create view v_customer
as
select Col1,Col2 from dbo.customer
union all
select Col1,Col2 from dbo.customer2007
union all
select Col1,Col2 from dbo.customer2008
go
--3.为索引视图创建唯一聚集索引
create unique clustered index cust_uniquetb on v_customer_sch_index(Col1)
go
--4.查看聚集索引有多少行以及视图占用多少空间
EXECUTE sp_spaceused 'v_customer_sch_index'
--5.查询索引视图强制走索引(with (NOEXPAND) )
select * from run.dbo.v_customer_sch_index with (NOEXPAND) where Col1='998628'
--6.再次插入数据的执行计划
INSERT INTO run.dbo.customer SELECT * FROM run.dbo.customer2008
最新文章
- BeautifulSoup Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.
- AO安装需要Microsoft Visual Studio 2013?
- 生成javadoc
- js运动框架完成块的宽高透明度及颜色的渐变
- Android中RelativeLayout属性详细说明
- 大型HashMap
- Node.js回调概念
- Spring Cp30配置
- Zimbra8.x邮件服务器安装及配置
- Java 小型学生管理系统心得
- lucene4.6 索引创建和搜索例子
- stretchlim函数分析
- chapter 10 统计检验
- python 面对post分页爬虫
- mysql插入大数据
- win7系统内网共享打印机设置
- springmvc的dispatchservlet初始化
- Elasticsearch实践(二):搜索
- 我的集合学习笔记--ArrayList
- 【Java】-NO.16.EBook.4.Java.1.008-【疯狂Java讲义第3版 李刚】- 集合/容器
热门文章
- Android netty客户端入门
- LOJ #10131 「一本通 4.4 例 2」暗的连锁
- Design Compressed String Iterator
- TIME_WAIT和CLOSE_WAIT的区别
- lxml and 代理ip
- linux 安装telnet
- 服务器爆满:cannot create temp file for here-document: No space left on device
- luogu题解 P3763 【[TJOI2017]DNA】
- luogu1156垃圾陷阱题解--背包DP
- plsql developer字符集和oracle字符集不一致的解决方法(转)