在 Sql Server 2008 中为视图建立索引实际上会复制原始数据吗?
如果我创建索引视图(在 Sql Server 2008 中),这是否意味着我将所有必需的数据从源表复制到单独的新表中?或者只保存一些微小的指针/索引来表示这个视图?
If i create an Indexed View (in Sql Server 2008), does this mean i copy all required the data from the source tables into a separate new table? Or are only some tiny pointers/indexes saved, to represent this view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,数据是单独复制和存储的,因此如果您修改基础表,您的索引视图将自动更新。 这会导致大量的锁争用。此外,索引视图可能会变得比基础表更大并变得适得其反。
Yes, the data is copied and stored separately, so if you modify the underlying table, your indexed view will update automatically. This causes a lot of lock contention. Also the indexed view may grow larger than the underlying tables and become counterproductive.
是的,数据被复制了。其他数据库平台(例如 Oracle)将此称为物化视图,因为数据将物质化为物理形式。
Yes, the data is copied. Other database platforms such as Oracle refer to this as a Materialized View because the data will materialize into a physical form.
当在视图上创建唯一聚集索引时,结果集将存储在数据库中,就像存储具有聚集索引的表一样。
当对基表中的数据进行修改时,数据修改也会反映出来在索引视图中存储的数据
~来自msdn
When a unique clustered index is created on a view, the result set is stored in the database just like a table with a clustered index is stored.
As modifications are made to the data in the base tables, the data modifications are reflected in the data stored in the indexed view
~ from msdn
您可以使用(未记录但广泛使用的)
DBCC PAGE
命令来准确查看存储的内容。下面将创建一个索引视图并打印第一个数据页的内容。You can use the (undocumented but widely used)
DBCC PAGE
command to see exactly what is stored. The following will create an indexed view and print the contents of the first data page.