您自己不声明 datatype 或可空性
CREATE TABLE [dbo].[tblLocations](
[latitude] [float] NOT NULL,
[longitude] [float] NOT NULL,
[location] [varchar](500) NOT NULL,
[timestamp] [datetime] NOT NULL,
[point] AS geography::Point(latitude, longitude, 4326)
)
通常,SQL Server 会假定该列可以为空 unless you add an ISNULL() around the formula。
但是我只是尝试了以下列定义
[point2] AS ISNULL(geography::Point(latitude, longitude, 4326),
geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326))
并且在sys.computed_columns 中仍然显示为is_nullable,因此它看起来不适用于CLR 数据类型(可能是因为SQL Server 不相信这些是确定性的)。
编辑:但是,只要计算列标记为PERSISTED,即
,指定
NOT NULL 在语法上是有效的
[point] AS geography::Point(latitude, longitude, 4326) PERSISTED NOT NULL
在这种特殊情况下,但是尝试使用这样的定义创建表会导致运行时错误。
表中的计算列“点”
'foo' 不能持久化,因为
列类型“地理”是
非字节排序的 CLR 类型。