使用计算列将现有表转换为时态表(用户定义函数)

时间:2019-03-20 07:14:39

标签: sql sql-server user-defined-functions calculated-columns temporal-tables

我想将现有表转换为时态表,并且它具有2个计算列(用户定义函数)。

我已经使用下面的脚本将3列添加到表中,并且操作成功。

Alter Table Trips
Add StartTime DateTime2 (2) GENERATED ALWAYS AS ROW START HIDDEN
        constraint df_StartTime default DateAdd(second, -1, SYSUTCDATETIME()),
    EndTime DateTime2 (2) GENERATED ALWAYS AS ROW END HIDDEN
        constraint df_EndTime default '9999.12.31 23:59:59.99',
    Period For System_Time (StartTime, EndTime)
Go

但是当我尝试执行以下脚本时

Alter Table Trips
    SET(SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.Trips_History))
Go

我在下面收到错误消息

Msg 13585, Level 16, State 1, Line 19
Computed column is defined with a user-defined function which is not allowed with system-versioned table 'AccessBetaX.dbo.Trips' because it performs user or system data access, or is assumed to perform this access. A function is assumed by default to perform data access if it is not schemabound.

我错过了重要的事情吗?

0 个答案:

没有答案