CREATE TABLE [D160-13-1].[DSAHIST_KP_UDBETALING_T](
  [ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [PERSON_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [VIRKSOMHED_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [UDBETALINGS_ORGANISATIONS_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [NEMKONTOBATCH_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [DISPOSITIONSDATO] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [BELOEB] [varchar](16) COLLATE Norwegian_100_CI_AS NULL,
  [IMPORTERET_TIL_KOMBIT] [varchar](3) COLLATE Norwegian_100_CI_AS NULL,
  [STRAKSUDBETALING] [varchar](3) COLLATE Norwegian_100_CI_AS NULL,
  [ANTAL_GENSENDELSER] [varchar](16) COLLATE Norwegian_100_CI_AS NULL,
  [TEKST_TIL_MODTAGER] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [UDBETALINGSFORHOLD] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [POSTERING_STATUS] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [LOS_ID] [varchar](35) COLLATE Norwegian_100_CI_AS NULL,
  [TYPE] [varchar](50) COLLATE Norwegian_100_CI_AS 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,
  [VERSION] [int] NULL,
  [TENANT_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [NKS_BETALINGSIDENTIFIKATION] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [NKS_BUNDTREFERENCE] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [TREDJEPART] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [OVERFOERSEL_METODE] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [BETALINGSMODTAGER_PERSON_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [SENSITIVITY] [varchar](20) 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],[PERSON_ID],[VIRKSOMHED_ID],[UDBETALINGS_ORGANISATIONS_ID],[NEMKONTOBATCH_ID],[DISPOSITIONSDATO],[BELOEB],[IMPORTERET_TIL_KOMBIT],[STRAKSUDBETALING],[ANTAL_GENSENDELSER],[TEKST_TIL_MODTAGER],[UDBETALINGSFORHOLD],[POSTERING_STATUS],[LOS_ID],[TYPE],[OPRETTET],[OPRETTETAF],[AENDRET],[AENDRETAF],[VERSION],[TENANT_ID],[NKS_BETALINGSIDENTIFIKATION],[NKS_BUNDTREFERENCE],[TREDJEPART],[OVERFOERSEL_METODE],[BETALINGSMODTAGER_PERSON_ID],[SENSITIVITY])),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_UDBETALING_T] On [D160-13-1].[DSAHIST_KP_UDBETALING_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 udbetaling kan enten være til borgers NemKonto eller til en kommune. En udbetaling kan dække flere ydelser samt flere træk, de vil dog alle have samme dispositionsdato', 
@level0type = N'SCHEMA', @level0name = N'D160-13-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KP_UDBETALING_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_UDBETALING_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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'PERSON_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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'VIRKSOMHED_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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'UDBETALINGS_ORGANISATIONS_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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'NEMKONTOBATCH_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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'DISPOSITIONSDATO';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'BELOEB';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'IMPORTERET_TIL_KOMBIT';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'STRAKSUDBETALING';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'ANTAL_GENSENDELSER';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'TEKST_TIL_MODTAGER';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'UDBETALINGSFORHOLD';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'POSTERING_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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'LOS_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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'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_UDBETALING_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_UDBETALING_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_UDBETALING_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_UDBETALING_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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'VERSION';
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_UDBETALING_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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'NKS_BETALINGSIDENTIFIKATION';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'NKS_BUNDTREFERENCE';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'TREDJEPART';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'OVERFOERSEL_METODE';
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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'BETALINGSMODTAGER_PERSON_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_UDBETALING_T', 
@level2type = N'COLUMN', @level2name = N'SENSITIVITY';
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_UDBETALING_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_UDBETALING_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_UDBETALING_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_UDBETALING_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_UDBETALING_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_UDBETALING_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_UDBETALING_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_UDBETALING_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_UDBETALING_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_UDBETALING_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_UDBETALING_T';
GO

