无法在视图“View_Table_Name”上创建索引,因为视图不是架构绑定的 [英] Cannot create index on view 'View_Table_Name' because the view is not schema bound
问题描述
我在存储过程(SQL-Server)中使用了Views。为了提高性能,我尝试创建该视图的INDEX。
I am using Views in my stored Procedure(SQL-Server). For Improving Performance, I have tried to created INDEX of that View.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW VW_Table_Name
AS
SELECT Col1,Col2,Col3 FROM Table_Name
GO
CREATE UNIQUE CLUSTERED INDEX Index_Name ON [VW_Table_Name](Col1)
GO
这里我得到错误
Msg 1939,Level 16,State 1,Line 1
无法在视图'VW_FML'上创建索引,因为视图不是模式绑定的。
Msg 1939, Level 16, State 1, Line 1 Cannot create index on view 'VW_FML' because the view is not schema bound.
我们可以在SQL Server中为View创建索引吗?
Can we created Index for View in SQL Server ?
推荐答案
索引视图有许多限制:没有子查询,没有联合,没有外连接等。请参阅本文了解更多详情。但是对于您的情况,您只需要使用模式绑定创建视图。
There are a number of restrictions on indexed views: no subqueries, no unions, no outer joins, etc. See this article for more details. But for your case, you simply need to create the view with schema binding.
CREATE VIEW VW_Table_Name WITH SCHEMABINDING
AS
SELECT Col1,Col2,Col3 FROM Table_Name
GO
这篇关于无法在视图“View_Table_Name”上创建索引,因为视图不是架构绑定的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!