funktioniert ab SQL Server 2016
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/* System Versionisierung wieder deaktivieren */ --ALTER TABLE dbo.MyTable SET (SYSTEM_VERSIONING = OFF) --ALTER TABLE dbo.MyTable DROP PERIOD FOR SYSTEM_TIME; --GO --ALTER TABLE [dbo].[MyTable] DROP CONSTRAINT [DF_MyTable_ValidFrom]; --GO --ALTER TABLE [dbo].[MyTable] DROP COLUMN [ValidFrom]; --GO --ALTER TABLE [dbo].[MyTable] DROP CONSTRAINT [DF_MyTable_ValidTo]; --GO --ALTER TABLE [dbo].[MyTable] DROP COLUMN [ValidTo]; /* System Versionisierung aktivieren */ -- Neue Spalten hinzugügen: ValidFrom, ValidTo ALTER TABLE dbo.MyTable ADD [ValidFrom] datetime2(7) GENERATED ALWAYS AS ROW START HIDDEN CONSTRAINT DF_MyTable_ValidFrom DEFAULT DATEADD(SECOND,-1, SYSUTCDATETIME()), ValidTo datetime2(7) GENERATED ALWAYS AS ROW END HIDDEN CONSTRAINT DF_MyTable_ValidTo DEFAULT CONVERT(datetime2 (7), '9999-12-31 23:59:59.9999999'), PERIOD FOR SYSTEM_TIME ([ValidFrom], ValidTo); GO -- History Tabelle erzeugen ALTER TABLE dbo.MyTable SET(SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.MyTable_History, DATA_CONSISTENCY_CHECK = ON)) GO |
Login