gpt4 book ai didi

tsql - 计算列帮助-TSQL

转载 作者:行者123 更新时间:2023-12-05 00:38:14 28 4
gpt4 key购买 nike

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
)

单词 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)
)

通常,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))

并且仍显示为 is_nullable中的 sys.computed_columns,因此它不适用于CLR数据类型(可能是因为SQL Server不相信这些是确定性的)。

编辑:但是,在语法上指定 NOT NULL是有效的,只要将计算列标记为 PERSISTED,即
[point] AS geography::Point(latitude, longitude, 4326) PERSISTED NOT NULL

但是,在这种特定情况下,尝试使用这种定义创建表会产生运行时错误。

Computed column 'point' in table 'foo' cannot be persisted because the column type, 'geography', is a non-byte-ordered CLR type.

关于tsql - 计算列帮助-TSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5841876/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com