And*_*ers 3 sql-server view disk-space
这个说法正确吗?
在幕后 SQL Server 实际上将视图中的数据存储为物理表,如果视图背后的任何数据发生更改,则必须更新该物理表
我做了一些搜索,但找不到任何关于视图如何在 SQL Server 中工作的资源。我一直认为除非您使用索引/物化视图,否则视图不会占用任何额外的数据空间。
谢谢
你的想法是正确的。以非索引视图为例:
创建测试视图:
use AdventureWorks2012;
go
create view dbo.DepartmentView
as
select
Name,
GroupName
from HumanResources.Department;
go
Run Code Online (Sandbox Code Playgroud)
现在,如果您要查看SELECT
视图上 a 的执行计划:
select *
from dbo.DepartmentView;
Run Code Online (Sandbox Code Playgroud)
您可以在下面看到引用了基础表的索引 ( HumanResources.Department
):
同样,当您更新视图时,您将看到类似的行为:
update dbo.DepartmentView
set GroupName = 'QA'
where GroupName = 'Quality Assurance';
Run Code Online (Sandbox Code Playgroud)
您还可以针对系统目录视图编写一些查询,以显示唯一保留的是视图的定义:
-- see the object in sys.objects
select *
from sys.objects
where object_id = object_id('dbo.DepartmentView');
-- ensure there are no indexes related to this view object
select *
from sys.indexes
where object_id = object_id('dbo.DepartmentView');
-- the definition is persisted
select
object_name(object_id) as object_name,
definition
from sys.sql_modules
where object_id = object_id('dbo.DepartmentView');
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
99 次 |
最近记录: |