一、注意点

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

最新文章

  1. BeautifulSoup Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.
  2. AO安装需要Microsoft Visual Studio 2013?
  3. 生成javadoc
  4. js运动框架完成块的宽高透明度及颜色的渐变
  5. Android中RelativeLayout属性详细说明
  6. 大型HashMap
  7. Node.js回调概念
  8. Spring Cp30配置
  9. Zimbra8.x邮件服务器安装及配置
  10. Java 小型学生管理系统心得
  11. lucene4.6 索引创建和搜索例子
  12. stretchlim函数分析
  13. chapter 10 统计检验
  14. python 面对post分页爬虫
  15. mysql插入大数据
  16. win7系统内网共享打印机设置
  17. springmvc的dispatchservlet初始化
  18. Elasticsearch实践(二):搜索
  19. 我的集合学习笔记--ArrayList
  20. 【Java】-NO.16.EBook.4.Java.1.008-【疯狂Java讲义第3版 李刚】- 集合/容器

热门文章

  1. Android netty客户端入门
  2. LOJ #10131 「一本通 4.4 例 2」暗的连锁
  3. Design Compressed String Iterator
  4. TIME_WAIT和CLOSE_WAIT的区别
  5. lxml and 代理ip
  6. linux 安装telnet
  7. 服务器爆满:cannot create temp file for here-document: No space left on device
  8. luogu题解 P3763 【[TJOI2017]DNA】
  9. luogu1156垃圾陷阱题解--背包DP
  10. plsql developer字符集和oracle字符集不一致的解决方法(转)