sla*_*dau 4 t-sql calculated-columns
CREATE TABLE [dbo].[tblLocations](
[latitude] [float] NOT NULL,
[longitude] [float] NOT NULL,
[location] [varchar](500) NOT NULL,
[timestamp] [datetime] NOT NULL,
[point] [geography] AS geography::Point(latitude, longitude, 4326) NOT NULL
)
Run Code Online (Sandbox Code Playgroud)
在这个词上给我不好的语法AS.
这不是你如何声明计算列?
你自己没有声明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)
)
Run Code Online (Sandbox Code Playgroud)
通常,SQL Server将假定该列可以为空,除非您ISNULL()在公式周围添加.
但是我只是尝试了以下列定义
[point2] AS ISNULL(geography::Point(latitude, longitude, 4326),
geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326))
Run Code Online (Sandbox Code Playgroud)
而且还表现为is_nullable在sys.computed_columns所以它看起来并不像一个适用于CLR数据类型(可能是因为SQL Server不相信这些是确定的).
编辑:但是只要计算列标记为ie,就在语法上有效NOT NULLPERSISTED
[point] AS geography::Point(latitude, longitude, 4326) PERSISTED NOT NULL
Run Code Online (Sandbox Code Playgroud)
但是,在这种特殊情况下,尝试创建具有此类定义的表会产生运行时错误.
表'foo'中的计算列'point'无法保留,因为列类型'geography'是非字节顺序的CLR类型.