---------------------------------------------------------------------
-- Query para convertir la tabla SAACXC en Auditable o Versionable --
-- Por Alessandro Muggia  2021                                     --
---------------------------------------------------------------------
-- Cambia el nombre de la Base de Datos--
Use Enterpriseadmindb
GO

CREATE SCHEMA H;
GO

  ALTER TABLE saacxc
    ADD
        SysStartTime DATETIME2 GENERATED ALWAYS AS ROW START HIDDEN
            CONSTRAINT DF_SysStart DEFAULT SYSUTCDATETIME()
      , SysEndTime DATETIME2 GENERATED ALWAYS AS ROW END HIDDEN
            CONSTRAINT DF_SysEnd DEFAULT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999'),
        PERIOD FOR SYSTEM_TIME (SysStartTime, SysEndTime);
GO

ALTER TABLE saacxc
    SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = H.saacxc,DATA_CONSISTENCY_CHECK = ON));

