`
中华好儿孙
  • 浏览: 65985 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

SqlServer里创建物化视图

    博客分类:
  • sql
阅读更多
create view v_familyInsurancesLookup WITH SCHEMABINDING as (
select company,
			 policyHolderName,
			 policyHolderId,
       insuredName,
       insuredCusId,
       age,
       validateDate,
       productName,
       maxpay,
       productCurrency,
       amount,
       modePremium,
       policyStatus,
       tid,
       agentNumber
 from (
					select 
                 t1.company as company,
					       t1.POLICY_HOLDER as policyHolderName,
					       t1.POLICY_HOLDER_id as policyHolderId,
       					   t1.recognizee as insuredName,
		   				   t1.recognizee_id as insuredCusId,
                   t1.age as age,
								t1.effective_date as validateDate,
								t2.name as productName,	
									t1.maxpay as maxpay,
       					   t1.currency as productCurrency,
       					   t2.amount as amount,
       					   t1.totalpay as modePremium,
       					   t1.insure_status as policyStatus,
                   t1.tid as tid,
                   t1.create_id as agentNumber,
			 		       row_number() over(partition by t1.tid order by t2.name) rname1 
					from dbo.gl_trade_policy t1
					     inner join 
					     dbo.gl_tradel_product t2
					     on 
					     t1.tid = t2.tradep_id and t1.status = '1' and t2.status = '1'
					     inner join
					     dbo.gl_cus_customer t3
					     on
					     t3.tid = t1.recognizee_id
					     inner join
					     dbo.gl_cus_customer t4
					     on
					     t4.tid = t1.POLICY_HOLDER_id) tt
	where tt.rname1 = 1
union
select null,
       policyHolderName,
       policyHolderId,
       insuredName,
       insuredCusId,
       age,
       validateDate,
       productName,
       maxpay,
			 productCurrency,
       amount,
       modePremium,
       policyStatus,
       tid,
       agentNumber
		from (select
    t2.policy_holder_name as policyHolderName,
		t2.customer_id as policyHolderId,
		t2.insured_name as insuredName,
		t3.customer_id as insuredCusId,
    t3.insured_age as age,
    t2.validate_date as validateDate,
    t4.product_name as productName,
		t3.payment_period as maxpay,
		t4.product_currency as productCurrency,
    t3.amount as amount,
    t2.MODE_PREMIUM as modePremium,
    t2.policy_status as policyStatus,
    t2.tid as tid,
    t5.agent_number as agentNumber,
		row_number() over(partition by t2.policy_code order by t3.coverage_sql asc) as rname1
		from dbo.gl_cus_accpect_manager t5
		inner join
		dbo.gl_cus_accept_insurance t2
		on t5.policy_code = t2.policy_code
		inner join
		dbo.gl_cus_polagent t3
		on
		t2.policy_code = t3.policy_code
		inner join
		dbo.gl_cus_accpect_product t4
		on
		t3.product_code = t4.product_code ) tt
		where tt.rname1 = 1)

怎样证明所创建的视图是物化视图而不是普通视图? -- 能在上面创建索引的视图就是物化视图
参考:http://www.cnblogs.com/liuzhendong/archive/2011/10/10/2205744.html
分享到:
评论

相关推荐

    SQL Server中用索引视图查看性能状况

    索引视图是一个已被物化或保存在数据库中的视图。当基本表更新时,给视图建立的索引由数据库引擎保存和更新。当你的结果集返回许多行并且需要求总数时,索引视图十分有用。这是因为数据库引擎必须在基表数据更新时...

    SQL Server 2008高级程序设计 4/6

    SQL Server 2008高级程序设计 4/6 SQL Server 2008 2010 高级程序设计 作者:(美)维埃拉 著,杨华,腾灵灵 译 出版社:清华大学 出版日期:2010-4-1 ISBN:9787302222729 字数:1250000 页码:730 ----------------...

    SQL Server 2008编程入门经典(第3版)

    第1章 RDBMS基础:SQLServer数据库的构成 1.1 数据库对象概述 1.1.1 数据库对象 1.1.2 事务日志 1.1.3 最基本的数据库对象:表 1.1.4 文件组 1.1.5 数据库关系图 1.1.6 视图 1.1.7 存储过程 1.1.8 用户自定义函数 ...

    SQL Server 2008高级程序设计 2/6

     8.9 索引(物化)视图  8.10 分区视图  8.11 小结 第9章 脚本和批处理  9.1 脚本的基本概念  9.2 批处理  9.3 SQLCMD  9.4 动态SQL:使用EXEC命令生成即时代码  9.5 流控制语句  9.6 小结 第10章 ...

    SQL.Server.2008编程入门经典(第3版).part2.rar

    第1章 RDBMS基础:SQLServer数据库的构成 1.1 数据库对象概述 1.1.1 数据库对象 1.1.2 事务日志 1.1.3 最基本的数据库对象:表 1.1.4 文件组 1.1.5 数据库关系图 1.1.6 视图 1.1.7 存储过程 1.1.8 用户自定义函数 ...

    SQL.Server.2008编程入门经典(第3版).part1.rar

    第1章 RDBMS基础:SQLServer数据库的构成 1.1 数据库对象概述 1.1.1 数据库对象 1.1.2 事务日志 1.1.3 最基本的数据库对象:表 1.1.4 文件组 1.1.5 数据库关系图 1.1.6 视图 1.1.7 存储过程 1.1.8 用户自定义函数 ...

    SQL Server 2008高级程序设计 5/6

    SQL Server 2008高级程序设计 5/6 SQL Server 2008 2010 高级程序设计 作者:(美)维埃拉 著,杨华,腾灵灵 译 出版社:清华大学 出版日期:2010-4-1 ISBN:9787302222729 字数:1250000 页码:730 ----------------...

    SQL Server 2008高级程序设计 6/6

    SQL Server 2008高级程序设计 6/6 SQL Server 2008 2010 高级程序设计 作者:(美)维埃拉 著,杨华,腾灵灵 译 出版社:清华大学 出版日期:2010-4-1 ISBN:9787302222729 字数:1250000 页码:730 ----------------...

    SQL Server 2008高级程序设计 1/6

     8.9 索引(物化)视图  8.10 分区视图  8.11 小结 第9章 脚本和批处理  9.1 脚本的基本概念  9.2 批处理  9.3 SQLCMD  9.4 动态SQL:使用EXEC命令生成即时代码  9.5 流控制语句  9.6 小结 第10章 ...

    SQL Server 2008高级程序设计 3/6

     8.9 索引(物化)视图  8.10 分区视图  8.11 小结 第9章 脚本和批处理  9.1 脚本的基本概念  9.2 批处理  9.3 SQLCMD  9.4 动态SQL:使用EXEC命令生成即时代码  9.5 流控制语句  9.6 小结 第10章 ...

    oracle database 10g 完整参考手册part1

    第24章 使用物化视图 第25章 使用Oracle Text进行文本搜索 第26章 使用外部表 第27章 使用回闪查询 第28章 回闪:表和数据库 第Ⅳ部分 Pl/SQL 第29章 PL/SQL简介 第30章 触发器 第31章 过程、函数与程序包 第32章 ...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

    说明:Oracle中需要创建用户一定是要具有dba(数据库管理员)权限的用户才能创建,而且创建的新用户不具备任何权限,连登录都不可以。 用法:create user 新用户名 identified by 密码 例子: 2. 修改密码 说明:...

    浅谈数据库优化方案

    分区将数据在物理上分隔开,不同分区的数据可以制定保存在处于不同磁盘上的数据文件里。这样,当对这个表进行查询时,只需要在表分区中进行扫描,而不必进行全表扫描,明显缩短了查询时间,另外处于不同磁盘的分区也...

Global site tag (gtag.js) - Google Analytics