CREATE TABLE [D160-12-1].[DSAHIST_KY_OpgaveH](
  [Aarsag] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [Aendret] [datetime2](3) NULL,
  [Aendretaf] [varchar](200) COLLATE Norwegian_100_CI_AS NULL,
  [AnsoegningId] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [BehandletAf] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [Beskrivelse] [varchar](500) COLLATE Norwegian_100_CI_AS NULL,
  [BrugervendtNoegle] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [EksekveretDato] [datetime2](3) NULL,
  [ErindringId] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [ErrorCount] [decimal](22,0) NULL,
  [Forfaldsdato] [datetime2](3) NULL,
  [GotoStepLimit] [datetime2](3) NULL,
  [HaendelseId] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [HistorikFra] [datetime2](3) NULL,
  [Id] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [Modtagelsesfrist] [datetime2](3) NULL,
  [Nulstillingsdato] [datetime2](3) NULL,
  [OperationType] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [Oprettet] [datetime2](3) NULL,
  [Oprettetaf] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [Paamindelsesdato] [datetime2](3) NULL,
  [PendingTime] [datetime2](3) NULL,
  [PersonId] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [Prioritet] [decimal](22,0) NULL,
  [ProcesmotorPrioritering] [decimal](22,0) NULL,
  [ReservedBy] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [RollbackLimit] [datetime2](3) NULL,
  [Status] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [SubType] [varchar](100) COLLATE Norwegian_100_CI_AS NULL,
  [Title] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [VirksomhedId] [varchar](50) COLLATE Norwegian_100_CI_AS 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([Aarsag],[Aendret],[Aendretaf],[AnsoegningId],[BehandletAf],[Beskrivelse],[BrugervendtNoegle],[EksekveretDato],[ErindringId],[ErrorCount],[Forfaldsdato],[GotoStepLimit],[HaendelseId],[HistorikFra],[Id],[Modtagelsesfrist],[Nulstillingsdato],[OperationType],[Oprettet],[Oprettetaf],[Paamindelsesdato],[PendingTime],[PersonId],[Prioritet],[ProcesmotorPrioritering],[ReservedBy],[RollbackLimit],[Status],[SubType],[Title],[VirksomhedId])),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_D160-12-1_DSAHIST_KY_OpgaveH] On [D160-12-1].[DSAHIST_KY_OpgaveH] (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'OpgaveH', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Aarsag';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Aendret';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Aendretaf';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'AnsoegningId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'BehandletAf';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Beskrivelse';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'BrugervendtNoegle';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'EksekveretDato';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'ErindringId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'ErrorCount';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Forfaldsdato';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'GotoStepLimit';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'HaendelseId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'HistorikFra';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Id';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Modtagelsesfrist';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Nulstillingsdato';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'OperationType';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Oprettet';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Oprettetaf';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Paamindelsesdato';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'PendingTime';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'PersonId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Prioritet';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'ProcesmotorPrioritering';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'ReservedBy';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'RollbackLimit';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Status';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'SubType';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'Title';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'VirksomhedId';
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'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@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'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@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'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@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'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@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'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@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'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@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'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@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'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'SYS_Checksum';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'SysExecutionId', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'SYS_ExecutionId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'SysDataDeliveryBatchIdCreate', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH', 
@level2type = N'COLUMN', @level2name = N'SYS_DataDeliveryBatchId_Create';
GO

EXEC sys.sp_addextendedproperty 
@name = N'DataArea', 
@value = N'ky', 
@level0type = N'SCHEMA', @level0name = N'D160-12-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KY_OpgaveH';
GO

