我有几个 system_versioned 表,并通过 SSDT 将项目部署到 Azure SQL 托管实例。对于这些 system_versioned 表中的许多表,SSDT 总是重新创建发布代码或将这些表显示为模式比较不同(见下图)。
在我看来,SSDT 无法更新 history_retention_parameter。对于某些表,但并非所有发生此部署行为的表,这已更改。此表的发布脚本包含以下步骤:
- 删除 system_versioning
- 打印“更改表 XY”
- 没做什么
- 添加 system_versioning ,请参见下面的摘录:
GO
PRINT N'Dropping system-versioning from [adf].[sourceConfig]...';
GO
IF EXISTS (SELECT TOP 1 1
FROM [sys].[tables]
WHERE [name] = N'sourceConfig'
AND SCHEMA_NAME(schema_id) = N'adf'
AND temporal_type = 2)
BEGIN
ALTER TABLE [adf].[sourceConfig] SET (SYSTEM_VERSIONING = OFF);
END
GO
PRINT N'Altering [adf].[sourceConfig]...';
GO
PRINT N'Adding system-versioning to [adf].[sourceConfig]...';
GO
ALTER TABLE [adf].[sourceConfig] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE=[adf].[sourceConfig_HISTORY], DATA_CONSISTENCY_CHECK=ON));
GO
PRINT N'Update complete.';
Schema Compare 如下所示(它显示为无法识别 history_retention_period 参数):但是,如果我检查 sys.tables
一般来说,这些表定义如下:
CREATE TABLE [ecc].[A0] AS
[someColumnes] DATATYPE NOT NULL [...],
[odsValidFrom] DATETIME2(7) GENERATED ALWAYS AS ROW START NOT NULL,
[odsValidTo] DATETIME2(7) GENERATED ALWAYS AS ROW END NOT NULL,
PRIMARY KEY CLUSTERED ([hashKey] ASC),
PERIOD FOR SYSTEM_TIME([odsValidFrom], [odsValidTo])
)
WITH (
SYSTEM_VERSIONING = ON (
HISTORY_TABLE = [ecc].[A0_HISTORY],
DATA_CONSISTENCY_CHECK = ON,
HISTORY_RETENTION_PERIOD = 7 DAY
)
);
Visual Studio:2019 企业版 16.8.1