-2
我在数据库中创建下面的函数错误在
Create FUNCTION [dbo].[CountUseer](@couponid INT)
RETURNS INT
AS
BEGIN
RETURN
(
SELECT Count(cu.id) NofUses --- this can only return one column
FROM Coupon as c
JOIN CouponUse as cu
ON c.id = cu.couponid
WHERE cu.couponid = @couponid
)
END
然后我运行此查询
ALTER TABLE dbo.Coupon
ADD NofUses AS dbo.CountUseer(Id)
现在,当我尝试在创建索引在SQL Server中的列上创建索引列:
CREATE INDEX Noofusesindex ON Coupon (NofUses)
我得到这个错误:
Column 'NofUses' in table 'Coupon' cannot be used in an index or statistics or as a partition key because it is non-deterministic.