SqlServer里创建物化视图

阅读更多
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,SQL,Server,视图,物化视图)