CREATE TABLE [D140-11-2].[DSAHIST_04_PersonStatusContactGroupHistory](
  [ContactGroupHistoryID] [int] NULL,
  [ContactGroupIdentifier] [nvarchar](100) COLLATE Norwegian_100_CI_AS NULL,
  [CivilRegistrationIdentifier] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [ContactGroupTypeIdentifier] [int] NULL,
  [StartDate] [datetime2](3) NULL,
  [EndDate] [datetime2](3) NULL,
  [RegistrationDeleted] [bit] NULL,
  [RegistrationDate] [datetime2](3) NULL,
  [EventDate] [datetime2](3) NULL,
  [AuthorityTypeId] [smallint] NULL,
  [AuthorityCode] [int] NULL,
  [CaseWorkerRID] [nvarchar](64) COLLATE Norwegian_100_CI_AS NULL,
  [PersonCaseStatus] [smallint] NULL,
  [ContactGroupEventTime] [datetime2](3) NULL,
  [SYS_KommuneId] [int] NULL,
  [SYS_BatchDate] [datetime2](3) NULL,
  [SYS_RowID] [bigint] identity(1,1) NOT NULL,
  [SYS_ExtractDate] [datetime2](3) NULL,
  [SYS_SourceFileID] [varchar](80) COLLATE Norwegian_100_CI_AS NULL,
  [SYS_RettelserTidAngivelse] [datetime2](3) NULL,
  [SYS_VersionID] [bigint] NULL,
  [SYS_Checksum] AS (CONVERT([bigint],hashbytes('SHA2_256',concat([ContactGroupHistoryID],[ContactGroupIdentifier],[CivilRegistrationIdentifier],[ContactGroupTypeIdentifier],[StartDate],[EndDate],[RegistrationDeleted],[RegistrationDate],[EventDate],[AuthorityTypeId],[AuthorityCode],[CaseWorkerRID],[PersonCaseStatus],[ContactGroupEventTime])),0)) PERSISTED,
  [SYS_ExecutionId] [bigint] NULL,
  [SYS_DataDeliveryBatchId_Create] [bigint] NULL
) 
on sys_batch_date_sc(SYS_BatchDate)
GO

CREATE UNIQUE CLUSTERED INDEX [IDX_CL_D140-11-2_DSAHIST_04_PersonStatusContactGroupHistory] On [D140-11-2].[DSAHIST_04_PersonStatusContactGroupHistory] (SYS_BatchDate, SYS_KommuneId, SYS_RowID) with (data_compression = page, STATISTICS_INCREMENTAL = ON) on sys_batch_date_sc(SYS_BatchDate);
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Historik tabel for lediges kontaktgrupper', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Id på tblPersonStatusContactGroupHistory', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'ContactGroupHistoryID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Unik identifikation af kontaktgruppen.', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'ContactGroupIdentifier';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Borgerens cpr nr.', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'CivilRegistrationIdentifier';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Kontaktgruppen, som den ledige har på beregnings-tidspunkt.', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'ContactGroupTypeIdentifier';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Startdato for den lediges kontaktgruppe', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'StartDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Slutdato for den lediges kontaktgruppe', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'EndDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Er registrering opdateret', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'RegistrationDeleted';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Registreringsdato fra DFDG', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'RegistrationDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Hændelsesdatoen', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'EventDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Myndighedstype der har foretaget registreringen', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'AuthorityTypeId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Myndighedskoden der har foretaget registreringen', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'AuthorityCode';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Sagsbehandlerens RID fra medarbejder OCES certifikatet', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'CaseWorkerRID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Angiver om personen har en aktiv sag. En sag kan på et givent tidspunkt have følgende status: Aktiv, Inaktiv eller Lukket. Status-skiftet er en afledt handling, dvs. en bruger kan ikke direkte skifte status på en sag', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'PersonCaseStatus';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Kontaktgruppes hændelsesdato', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'ContactGroupEventTime';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder nummeret på den kommune, som rækken tilhører', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'SYS_KommuneId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder information om, hvilken batch rækken er indlæst i', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'SYS_BatchDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder et fortløbende nummer, så alle rækker i tabellen har et unikt nummer', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'SYS_RowID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder det dato stempel, som kildefilen er markeret med', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'SYS_ExtractDate';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder ID for den primære snitflade, hvor data i rækken stammer fra', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'SYS_SourceFileID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder den forretningsmæssige tidsangivelse for rækken. Denne bruges hvis data skal slettes med tidsangivelse', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'SYS_RettelserTidAngivelse';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder et versionsnummer for den pågældende række', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'SYS_VersionID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Dette er en teknisk Kolonne i FLIS. Indeholder cheksum info', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'SYS_Checksum';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'SysExecutionId', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'SYS_ExecutionId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'SysDataDeliveryBatchIdCreate', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory', 
@level2type = N'COLUMN', @level2name = N'SYS_DataDeliveryBatchId_Create';
GO

EXEC sys.sp_addextendedproperty 
@name = N'DataArea', 
@value = N'dfdg', 
@level0type = N'SCHEMA', @level0name = N'D140-11-2', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_04_PersonStatusContactGroupHistory';
GO

