SQL Server 索引视图列精度
我正在尝试创建索引视图并在创建索引时出现以下错误:
无法在视图上创建索引 ....' 因为列“金额”被视图引用 WHERE 或 GROUP BY 子句不精确。考虑消除该列 从视图中,或者更精确地更改列。
有问题的列的数据类型为 real
我猜这就是问题所在?
解决这个问题的适当方法是什么?我可以在视图 SQL 中进行转换以消除“不精确性”吗?
视图SQL指定如下:
EXEC('
CREATE VIEW model.ReceivableBillableParties
WITH SCHEMABINDING
AS
SELECT pf.Id AS Id
, pf.InsuranceId AS InsuranceId
, pf.FinancialInsType AS InsuranceType
, pr.ReceivableId
FROM dbo.Receivables pr
INNER JOIN dbo.Demographics pd ON pd.PersonId = pr.PersonId
INNER JOIN dbo.Appointments ap ON ap.AppointmentId = pr.AppointmentId
INNER JOIN dbo.Financiasl pf ON pf.PersonId = pf.PersonId
INNER JOIN dbo.PracticeInsurers pri ON pri.InsurerId = pf.FinancialInsurerId
WHERE pri.Amount = 0
')
EXEC('
CREATE UNIQUE CLUSTERED INDEX [IX_ReceivableBillableParties]
ON model.ReceivableBillableParties ([Id]);
')
I'm trying to create an indexed view and get the following error creating the index:
Cannot create index on view
....'
because column 'Amount' that is referenced by the view in the
WHERE or GROUP BY clause is imprecise. Consider eliminating the column
from the view, or altering the column to be precise.
The column in question has a data type of real
which I guess is the problem?
What's the appropriate way of resolving this? Can I do a convert in the view SQL to eliminate the "impreciseness"?
The view SQL is specified below:
EXEC('
CREATE VIEW model.ReceivableBillableParties
WITH SCHEMABINDING
AS
SELECT pf.Id AS Id
, pf.InsuranceId AS InsuranceId
, pf.FinancialInsType AS InsuranceType
, pr.ReceivableId
FROM dbo.Receivables pr
INNER JOIN dbo.Demographics pd ON pd.PersonId = pr.PersonId
INNER JOIN dbo.Appointments ap ON ap.AppointmentId = pr.AppointmentId
INNER JOIN dbo.Financiasl pf ON pf.PersonId = pf.PersonId
INNER JOIN dbo.PracticeInsurers pri ON pri.InsurerId = pf.FinancialInsurerId
WHERE pri.Amount = 0
')
EXEC('
CREATE UNIQUE CLUSTERED INDEX [IX_ReceivableBillableParties]
ON model.ReceivableBillableParties ([Id]);
')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档确实指出了该问题取决于
real
数据类型(请参阅精度要求)。如果您想在视图的WHERE
子句中使用该列,并为该视图建立索引,则需要将该列更改为精确的数据类型(即DECIMAL(9, 2)
)。编辑
此文档更清晰地解释了为何存在此限制。来自“确定性函数”部分:
希望有所帮助。
The documentation does indicate that the problem lies with the
real
data type (see Precision Requirements). If you want to use that column in theWHERE
clause of your view, and index that view, you'll need to alter the column to a precise data type (i.e.,DECIMAL(9, 2)
).EDIT
This documentation provides a clearer explanation for why this restriction exists. From the section "Deterministic Functions":
Hope that helps.