Enable SQL Server system versioning : To enable SQL Server system versioning on existing table:

ALTER TABLE [database_name].[schema_name].[table_name]
ADD [SYS_START_DATETIME] DATETIME2 GENERATED ALWAYS AS ROW START HIDDEN NOT NULL DEFAULT SYSUTCDATETIME(), [SYS_END_DATETIME] DATETIME2 GENERATED ALWAYS AS ROW END HIDDEN NOT NULL DEFAULT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999'),
PERIOD FOR SYSTEM_TIME ([SYS_START_DATETIME], [SYS_END_DATETIME])
GO
ALTER TABLE [database_name].[schema_name].[table_name]
SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE=[database_name].[schema_name].[table_name]))
GO
Tagged:

Laisser un commentaire