CREATE TABLE [D160-13-1].[DSAHIST_KP_ADRESSE_T](
  [ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [VIRKSOMHED_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [CPR_PERSON_ID] [varchar](36) COLLATE Norwegian_100_CI_AS NULL,
  [GYLDIG_FRA] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [GYLDIG_TIL] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [TYPE_KODE] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [REGISTRERING_TID] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [VEJ] [varchar](40) COLLATE Norwegian_100_CI_AS NULL,
  [KOMMUNENUMMER] [varchar](4) COLLATE Norwegian_100_CI_AS NULL,
  [HUSNUMMER] [varchar](5) COLLATE Norwegian_100_CI_AS NULL,
  [ETAGE] [varchar](2) COLLATE Norwegian_100_CI_AS NULL,
  [CO_NAVN] [varchar](40) COLLATE Norwegian_100_CI_AS NULL,
  [HISTORIK_INDIKATOR] [varchar](3) COLLATE Norwegian_100_CI_AS NULL,
  [ADRESSELINJE_1] [varchar](34) COLLATE Norwegian_100_CI_AS NULL,
  [ADRESSELINJE_2] [varchar](34) COLLATE Norwegian_100_CI_AS NULL,
  [ADRESSELINJE_3] [varchar](34) COLLATE Norwegian_100_CI_AS NULL,
  [ADRESSELINJE_4] [varchar](34) COLLATE Norwegian_100_CI_AS NULL,
  [ADRESSELINJE_5] [varchar](34) COLLATE Norwegian_100_CI_AS NULL,
  [POSTNUMMER] [varchar](4) COLLATE Norwegian_100_CI_AS NULL,
  [POSTBY] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [ADRESSERINGSNAVN] [varchar](40) COLLATE Norwegian_100_CI_AS NULL,
  [SIDE_DOER] [varchar](16) COLLATE Norwegian_100_CI_AS NULL,
  [LOKALITET] [varchar](160) COLLATE Norwegian_100_CI_AS NULL,
  [BYNAVN] [varchar](160) COLLATE Norwegian_100_CI_AS NULL,
  [POSTDISTRIKT] [varchar](40) COLLATE Norwegian_100_CI_AS NULL,
  [LAND] [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,
  [STANDARDADRESSE] [varchar](40) COLLATE Norwegian_100_CI_AS NULL,
  [VEJKODE] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [BYGNINGSNUMMER] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [UNIKADRESSE_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],[VIRKSOMHED_ID],[CPR_PERSON_ID],[GYLDIG_FRA],[GYLDIG_TIL],[TYPE_KODE],[REGISTRERING_TID],[VEJ],[KOMMUNENUMMER],[HUSNUMMER],[ETAGE],[CO_NAVN],[HISTORIK_INDIKATOR],[ADRESSELINJE_1],[ADRESSELINJE_2],[ADRESSELINJE_3],[ADRESSELINJE_4],[ADRESSELINJE_5],[POSTNUMMER],[POSTBY],[ADRESSERINGSNAVN],[SIDE_DOER],[LOKALITET],[BYNAVN],[POSTDISTRIKT],[LAND],[OPRETTET],[OPRETTETAF],[AENDRET],[AENDRETAF],[VERSION],[STANDARDADRESSE],[VEJKODE],[BYGNINGSNUMMER],[UNIKADRESSE_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_ADRESSE_T] On [D160-13-1].[DSAHIST_KP_ADRESSE_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 persons adresse. En adresse kan enten være dansk, udenlandsk eller blot et kontaktsted', 
@level0type = N'SCHEMA', @level0name = N'D160-13-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KP_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'CPR_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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'GYLDIG_FRA';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'GYLDIG_TIL';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'TYPE_KODE';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'REGISTRERING_TID';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'VEJ';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'KOMMUNENUMMER';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'HUSNUMMER';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'ETAGE';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'CO_NAVN';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'HISTORIK_INDIKATOR';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'ADRESSELINJE_1';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'ADRESSELINJE_2';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'ADRESSELINJE_3';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'ADRESSELINJE_4';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'ADRESSELINJE_5';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'POSTNUMMER';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'POSTBY';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'ADRESSERINGSNAVN';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'SIDE_DOER';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'LOKALITET';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'BYNAVN';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'POSTDISTRIKT';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'LAND';
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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'STANDARDADRESSE';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'VEJKODE';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'BYGNINGSNUMMER';
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_ADRESSE_T', 
@level2type = N'COLUMN', @level2name = N'UNIKADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_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_ADRESSE_T';
GO

