SQL Server - Indexed Views

本文介绍了如何使用'SCHEMABINDING'创建SQL Server中的视图,并详细解释了创建带有集群索引的视图所需的步骤及约束条件。此外,还深入探讨了'SCHEMABINDING'的作用及其对底层表的影响。

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

 

1. Create the view with 'SCHEMABINDING'

CREATE VIEW [dbo].[vTest] WITH SCHEMABINDING AS
SELECT

 

2. Create the index

CREATE UNIQUE CLUSTERED INDEX idx_vTest ON vTest(IndexColumn)
 

3. Constrains:

  • The view must have been created with certain SET options, such as QUOTED_IDENTIFIER and CONCAT_NULL_YIELDS_NULL set to ON.
  • The session creating the index must also have the correct SET options.
  • Any user-defined function referenced by the view must have been created using WITH SCHEMABINDING.
  • The view must be deterministic (consistently providing the same result given the same input).
  • The base tables must have been created with the proper ANSI_NULLS setting.
  • The result set of the view is physically stored in the database, thus storage space for the clustered index is also a constraint to consider.

4. What is 'SCHEMABINDING'?

To put it simply, once you create a view with schemabinding, you cannot change the underlying tables in a way that would break the view.  Examples of this would be removing columns or dropping tables that are specified in the view.

 

5. Reference:

http://www.codeproject.com/Articles/199058/SQL-Server-Indexed-Views-Speed-Up-Your-Select-Quer

http://strangenut.com/blogs/dacrowlah/archive/2008/12/02/what-does-schemabinding-mean-in-sql-2005-and-2008.aspx

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值