在sql Server 2005中,我试图在索引视图中使用用户定义函数,该视图将用于全文索引.我已经能够让UDF使用存储过程和有问题的视图.但是,当我尝试在视图上创建索引时,我收到以下错误…
无法在视图“DevDatabase.dbo.View_PersonSearch”上创建索引,因为视图引用的函数“dbo.GetCurrentimage”执行用户或系统数据访问.
我很难过.以下是我想要做的一个例子.我错过了什么,或者这是否可能?
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[GetCurrentimage](@Person_ID int) RETURNS int WITH SCHEMABINDING AS BEGIN -- Declare the return variable here DECLARE @Img_ID int SET @Img_ID = (**sql that selects image** ) RETURN @Img_ID END GO
查看索引创建
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER VIEW [dbo].[View_PersonSearch] WITH SCHEMABINDING AS SELECT Person_ID,(**Select fields to search on**) AS SearchArea,dbo.GetCurrentimage(Person_ID) AS FK_Img_ID FROM dbo.Person GO CREATE UNIQUE CLUSTERED INDEX Index_Person_ID ON [View_PersonSearch](Person_ID) GO