Thanks to

MS sql could have materialized views ,similar with oracle MVs, using indexed views.

what is going on ? are they same thing ?

Here we go :

(1) general demo tables and rows

/****************************************************
AboutSQLServer.com blog
Written by Dmitri Korotkevitch
"Indexed views"
2011-03-24
*****************************************************/
set nocount on
go
set ANSI_NULLS on
set QUOTED_IDENTIFIER on
go

create table dbo.Clients
(
ClientId int not null,
ClientName varchar(32),
constraint PK_Clients
primary key clustered(ClientId)
)
go
create table dbo.Orders
(
OrderId int not null identity(1,1),
Clientid int not null,
OrderDate datetime not null,
OrderNumber varchar(32) not null,
Amount smallmoney not null,
Placeholder char(100) not null
constraint Def_Orders_Placeholder
default 'a',
constraint PK_Orders
primary key clustered(OrderId)
)
go

;with CTE(Num)
as
(
select 0
union all
select Num + 1
from CTE
where Num < 100
)
insert into dbo.Clients(Clientid, ClientName)
select Num, 'Client ' + convert(varchar(32),Num)
from CTE
option (MAXRECURSION 0)
go

;with CTE(Num)
as
(
select 0
union all
select Num + 1
from CTE
where Num < 100000
)
insert into dbo.Orders(Clientid, OrderDate, OrderNumber, Amount)
select
Num % 100,
DATEADD(day,-Num % 365, GetDate()),
'Order: ' + convert(varchar(32),Num),
Num % 100
from CTE
option (MAXRECURSION 0)
go

(2) -- no views select query
select
c.ClientId, c.ClientName,
count(o.OrderId) as [NumOfOrders],
sum(o.Amount) as [TotalAmount]
from
dbo.Clients c join dbo.Orders o on
c.ClientId = o.ClientId
group by
c.ClientId, c.ClientName
having
sum(o.Amount) > 90000
go

(9 row(s) affected)
Table 'Clients'. Scan count 0, logical reads 200, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Workfile'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Orders'. Scan count 1, logical reads 1823, physical reads 2, read-ahead reads 1798, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
(1 row(s) affected)

(3) creating indexing view
create view dbo.vClientWithOrders(
ClientId, ClientName,
NumOfOrders, TotalAmount
)
with schemabinding
as
select
c.ClientId, c.ClientName,
count_big(*) as NumOfOrders,
sum(o.Amount) as TotalAmount
from
dbo.Clients c join dbo.Orders o on
c.ClientId = o.ClientId
group by
c.ClientId, c.ClientName
go

create unique clustered index
IDX_vClientWithOrders_ClientId
on dbo.vClientWithOrders(ClientId)
go

--run again same query

(9 row(s) affected)
Table 'vClientWithOrders'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

-- only query from the view
select *
from dbo.vClientWithOrders
where TotalAmount > 90000
go

(9 row(s) affected)
Table 'vClientWithOrders'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

(4) With the standard edition of SQL Server, you can use ---with (noexpend)
select *
from dbo.vClientWithOrders with(noexpend)
where TotalAmount > 90000
go

and get the same result as above one

so,. let close it with MS web site words

Creating a unique clustered index on a view improves query performance because the view is stored in the database in the same way a table with a clustered index is stored. The query optimizer may use indexed views to speed up the query execution. The view does not have to be referenced in the query for the optimizer to consider that view for a substitution.

Indexed (materialized) views in SQL Server,different with Oracle (materialized) views的更多相关文章

  1. 在64位SQL Server中创建Oracle的链接服务器

    当我们同时使用SQL Server和Oracle来存储数据时,经常会用到跨库查询.为了方便使用跨库查询,一个最好的办法就是通过创建链接服务器来实现.既可以在SQL Server中创建Oracle的链接 ...

  2. 从 Microsoft SQL Server 迁移到 Oracle

    来源于:http://www.oracle.com/technetwork/cn/database/migration/sqlserver-095136-zhs.html Oracle SQL Dev ...

  3. SQL SERVER 2008向ORACLE 11G迁移示例

    来源于:http://www.cnblogs.com/hiizsk/ 由SQL SERVER 2008向ORACLE 11G迁移过程记录之一-表 使用Oracle Sql Developer将SQL ...

  4. 通过SQL Server 2008 访问Oracle 10g

    原文地址:http://www.cnblogs.com/gnielee/archive/2010/09/07/access-oracle-from-sqlserver.html 之前写过一篇关于SQL ...

  5. 在64位SQL Server中创建Oracle的链接服务器 Link Server

    有时候我们希望在一个sqlserver下访问另一个sqlserver数据库上的数据,或者访问其他oracle数据库上的数据,要想完成这些操作,我们首要的是创建数据库链接. 数据库链接能够让本地的一个s ...

  6. 【SQL Server数据迁移】64位的机器:SQL Server中查询ORACLE的数据

    从SQL Server中查询ORACLE中的数据,可以在SQL Server中创建到ORACLE的链接服务器来实现的,但是根据32位 .64位的机器和软件, 需要用不同的驱动程序来实现. 在64位的机 ...

  7. 【SQL Server数据迁移】32位的机器:SQL Server中查询ORACLE的数据

    从SQL Server中查询ORACLE中的数据,可以在SQL Server中创建到ORACLE的链接服务器来实现的,但是根据32位 .64位的机器和软件,需要用不同的驱动程序来实现. 在32位的机器 ...

  8. SQL Server 2008创建oracle链接服务器(心得)

    操作系统是32位的情况下,曾经没费太多时间创建好了到oracle的链接服务器.主要要点就是: 1.安装oracle精简客户端.当时我用的是版本比较低的“oracle9i310-客户端简化版”,安装好了 ...

  9. 大规模数据 从SQL SERVER导入到ORACLE方法

    来源于:http://blog.csdn.net/iitkd/article/details/40394789 来源:一个7G的SQL SERVER .bak文件要导入到Oracle中,经过实验,完成 ...

随机推荐

  1. bm坏字符 , Horspool算法 以及Sunday算法的不同

    bm坏字符 , Horspool算法 以及Sunday算法的不同 一.bm中的坏字符规则思想 (1)模式串与主串从后向前匹配 (2)发现坏字符后,如果坏字符不存在于模式串中:将模式串的头字符与坏字符后 ...

  2. opencv python:直线检测 与 圆检测

    霍夫直线变换介绍 霍夫圆检测 现实中: example import cv2 as cv import numpy as np # 关于霍夫变换的相关知识可以看看这个博客:https://blog.c ...

  3. vue基础笔记

    目录 Vue 渐进式 JavaScript 框架 一.走进Vue 二.Vue实例 三.生命周期钩子 四.Vue指令 五.组件 六.Vue-CLI 项目搭建 Vue 渐进式 JavaScript 框架 ...

  4. 微信-获取openid

    第一步 首先把微信的支付流程与相关的文档熟悉一遍,具体的支付逻辑是怎么实现的,心里要有一定的路数,开发的时候一边看文档,一边写,再一边调试这是最好的选择,首先阅读微信开发文档,因为我们这次是做公众号支 ...

  5. RTT学习之sensor设备

    Sensor设备的常用操作: 首先查找传感器设置获取设备句柄.rt_device_find 以轮询.FIFO.中断.任意一种方式打开传感器,中断和FIFO需要设置接收回调函数(释放一个信号量给接收线程 ...

  6. 洛谷 P1880 [NOI1995]石子合并(区间DP)

    嗯... 题目链接:https://www.luogu.org/problem/P1880 这道题特点在于石子是一个环,所以让a[i+n] = a[i](两倍长度)即可解决环的问题,然后注意求区间最小 ...

  7. Windows server 2012 R2 服务器用户自动锁定

    开启共享文件夹后,发现经常会自动锁定导致,共享用户无法正常访问共享文件夹(原因不明) 解决办法,打开本地安全策略 把账户锁定阈值改为0

  8. [题解] 2019牛客暑期多校第三场H题 Magic Line

    题目链接:https://ac.nowcoder.com/acm/contest/883/H 题意:二维平面上有n个不同的点,构造一条直线把平面分成两个点数相同的部分. 题解:对这n个点以x为第一关键 ...

  9. Vue组件介绍及开发

    一. 通过axios实现数据请求 1.json json是 JavaScript Object Notation 的首字母缩写,单词的意思是javascript对象表示法,这里说的json指的是类似于 ...

  10. 操作系统OS - 阻塞(Blocking)非阻塞(Non-Blocking)与同步(Synchronous)异步(Asynchronous)

    参考: http://blog.jobbole.com/103290/ https://www.zhihu.com/question/19732473/answer/23434554 http://b ...