문제

I get this error when creating a view: "Cannot schema bind view 'dbo.viewStock'. 'dbo.GetStockCurrentQuantityByProduct' is not schema bound."

BACKGROUND: What I actually want to achieve is improve the speed of a query that retrieves Product Id / Current Stock. The current stock is calculated by a function that counts the units in/units out for a specific product ('dbo.GetStockCurrentQuantityByProduct'). I am exploring a possible solution - creating an indexed view to hold product Ids and current stocks, so I can select directly from it for faster query execution:

    CREATE VIEW [dbo].[viewStock] with schemabinding
    as 
    SELECT P.ProductId, 
    dbo.GetStockCurrentQuantityByProduct(P.ProductId) AS Quantity 
    FROM dbo.Product 

When I execute this, I get the error:

    Cannot schema bind view 'dbo.viewStock'. 
'dbo.GetStockCurrentQuantityByProduct' is not schema bound.
도움이 되었습니까?

해결책

See the SCHEMABINDING option of CREATE FUNCTION or ALTER FUNCTION

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top