SqlServer里创建物化视图

本文探讨如何在Sql Server中创建物化视图,并通过能否在视图上建立索引来判断其是否为物化视图。物化视图在支持索引的情况下,能提供更快的数据访问速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)

[b]怎样证明所创建的视图是物化视图而不是普通视图? -- 能在上面创建索引的视图就是物化视图[/b]
参考:[url]http://www.cnblogs.com/liuzhendong/archive/2011/10/10/2205744.html[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值