CREATE TABLE [D160-13-1].[DSAHIST_KP_OPGAVE_T](
  [ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [ANSOEGNING_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [HAENDELSE_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [AARSAG] [varchar](100) COLLATE Norwegian_100_CI_AS NULL,
  [EKSEKVERET_DATO] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [TITLE] [varchar](500) COLLATE Norwegian_100_CI_AS NULL,
  [BESKRIVELSE] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [FORFALDSDATO] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [STATUS] [varchar](100) COLLATE Norwegian_100_CI_AS NULL,
  [PRIORITET] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [BEHANDLET_AF] [varchar](500) COLLATE Norwegian_100_CI_AS NULL,
  [ERINDRING_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [PAAMINDELSESDATO] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [MODTAGELSESFRIST] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [BRUGERVENDT_NOEGLE] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [PROCESMOTOR_PRIORITERING] [int] NULL,
  [RESERVED_BY] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [NULSTILLINGSDATO] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [SUB_TYPE] [varchar](100) COLLATE Norwegian_100_CI_AS NULL,
  [ROLLBACK_LIMIT] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [GOTO_STEP_LIMIT] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [PENDING_TIME] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [ERROR_COUNT] [int] NULL,
  [OPRETTET] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [OPRETTETAF] [varchar](500) COLLATE Norwegian_100_CI_AS NULL,
  [AENDRET] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [AENDRETAF] [varchar](500) COLLATE Norwegian_100_CI_AS NULL,
  [EXECUTION_HASH] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [TENANT_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [SENSITIVITY] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [KILDE] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [ENTITY_TYPE] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [ENTITY_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [AKTUELT_TRIN] [varchar](100) 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([ID],[ANSOEGNING_ID],[HAENDELSE_ID],[AARSAG],[EKSEKVERET_DATO],[TITLE],[BESKRIVELSE],[FORFALDSDATO],[STATUS],[PRIORITET],[BEHANDLET_AF],[ERINDRING_ID],[PAAMINDELSESDATO],[MODTAGELSESFRIST],[BRUGERVENDT_NOEGLE],[PROCESMOTOR_PRIORITERING],[RESERVED_BY],[NULSTILLINGSDATO],[SUB_TYPE],[ROLLBACK_LIMIT],[GOTO_STEP_LIMIT],[PENDING_TIME],[ERROR_COUNT],[OPRETTET],[OPRETTETAF],[AENDRET],[AENDRETAF],[EXECUTION_HASH],[TENANT_ID],[SENSITIVITY],[KILDE],[ENTITY_TYPE],[ENTITY_ID],[AKTUELT_TRIN])),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-13-1_DSAHIST_KP_OPGAVE_T] On [D160-13-1].[DSAHIST_KP_OPGAVE_T] (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'En opgave oprettes altid af procesmotoren som reaktion på at der er oprettet en Hændelse i status tilføjet, og identificeret et\nhændelsesabonnement som matcher hændelsens type til en given arbejdsgang', 
@level0type = N'SCHEMA', @level0name = N'D160-13-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KP_OPGAVE_T';
GO

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

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

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

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

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

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

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Datatype clob originalt', 
@level0type = N'SCHEMA', @level0name = N'D160-13-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KP_OPGAVE_T', 
@level2type = N'COLUMN', @level2name = N'BESKRIVELSE';
GO

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

EXEC sys.sp_addextendedproperty 
@name = N'DataArea', 
@value = N'kp', 
@level0type = N'SCHEMA', @level0name = N'D160-13-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KP_OPGAVE_T';
GO

