创建通知查询中描述了这些限制。没有提及 CLR 系统类型 ( geography
, geometry
, hierachyid
)。我之前已经描述了查询通知是如何在幕后工作的,如果您阅读那篇文章,您会发现查询通知的要求与索引视图的要求完全匹配(文章解释了为什么这并非巧合)。因此,如果您可以按照自己的意愿创建索引视图,查询通知应该可以工作。让我们尝试一下,使用 MSDN 示例:
CREATE TABLE SpatialTable
( id int IDENTITY (1,1),
GeogCol1 geography,
GeogCol2 AS GeogCol1.STAsText() );
GO
INSERT INTO SpatialTable (GeogCol1)
VALUES (geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326));
INSERT INTO SpatialTable (GeogCol1)
VALUES (geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326));
GO
create view vw_test
with schemabinding
as
select id, GeogCol1, GeogCol2
from dbo.SpatialTable
where geography::STGeomFromText('POINT(-122.35 47.656)',4326).STIntersects(GeogCol1) = 1;
go
create unique clustered index cdx_vw on vw_test (id)
go
消息 1982,级别 16,状态 1,第 1 行
无法在视图“test.dbo.vw_test”上创建索引,因为该视图在 CLR 类型“Microsoft.SqlServer.Types.SqlGeography”上引用了不确定或不精确的成员函数“STGeomFromText ”。考虑删除对函数的引用或更改函数以使其行为具有确定性。不要将行为不确定的 CLR 函数声明为具有 IsDeterministic=true,因为这会导致索引损坏。有关详细信息,请参阅联机丛书。
你来了:查询通知(以及所有其他派生类,如 SqlDependency)不适用于geography::STGeomFromText
函数。