CREATE TABLE [D220-10-21].[DSAHIST_AdresserMedDistrikter](
  [Adr_id] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [ObjStatus] [int] NULL,
  [kommunekode] [varchar](4) COLLATE Norwegian_100_CI_AS NULL,
  [vejkode] [varchar](4) COLLATE Norwegian_100_CI_AS NULL,
  [vejnavn] [varchar](40) COLLATE Norwegian_100_CI_AS NULL,
  [adresseringsvejnavn] [varchar](40) COLLATE Norwegian_100_CI_AS NULL,
  [husnr] [varchar](4) COLLATE Norwegian_100_CI_AS NULL,
  [etage] [varchar](2) COLLATE Norwegian_100_CI_AS NULL,
  [sidedoer] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [supplerendebynavn] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [postnr] [varchar](4) COLLATE Norwegian_100_CI_AS NULL,
  [postnrnavn] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [Lev_ID] [int] NULL,
  [Lev_DimTid] [int] NULL,
  [Lev_Dato] [datetime2](3) NULL,
  [temakode] [bigint] NULL,
  [temanavn] [varchar](200) COLLATE Norwegian_100_CI_AS NULL,
  [udd_distrikt_nr] [bigint] NULL,
  [udd_distrikt_navn] [varchar](200) COLLATE Norwegian_100_CI_AS NULL,
  [udd_distrikt_type_kode] [bigint] NULL,
  [udd_distrikt_type] [varchar](200) COLLATE Norwegian_100_CI_AS NULL,
  [starttrin_kode] [bigint] NULL,
  [starttrin] [varchar](200) COLLATE Norwegian_100_CI_AS NULL,
  [sluttrin_kode] [bigint] NULL,
  [sluttrin] [varchar](200) 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([Adr_id],[ObjStatus],[kommunekode],[vejkode],[vejnavn],[adresseringsvejnavn],[husnr],[etage],[sidedoer],[supplerendebynavn],[postnr],[postnrnavn],[Lev_ID],[Lev_DimTid],[Lev_Dato],[temakode],[temanavn],[udd_distrikt_nr],[udd_distrikt_navn],[udd_distrikt_type_kode],[udd_distrikt_type],[starttrin_kode],[starttrin],[sluttrin_kode],[sluttrin])),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_D220-10-21_DSAHIST_AdresserMedDistrikter] On [D220-10-21].[DSAHIST_AdresserMedDistrikter] (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'Beskrivelse af skoledistrikter til Borger området', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'Adr_id';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'ObjStatus';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'kommunekode';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'vejkode';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'vejnavn';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'adresseringsvejnavn';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'husnr';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'etage';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'sidedoer';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'supplerendebynavn';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'postnr';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'postnrnavn';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'Lev_ID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'Lev_DimTid';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'Lev_Dato';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'temakode';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'temanavn';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'udd_distrikt_nr';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'udd_distrikt_navn';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'udd_distrikt_type_kode';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'udd_distrikt_type';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'starttrin_kode';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'starttrin';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'sluttrin_kode';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'sluttrin';
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'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@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'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@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'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@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'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@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'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@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'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@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'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@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'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'SYS_Checksum';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'SysExecutionId', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'SYS_ExecutionId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'SysDataDeliveryBatchIdCreate', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter', 
@level2type = N'COLUMN', @level2name = N'SYS_DataDeliveryBatchId_Create';
GO

EXEC sys.sp_addextendedproperty 
@name = N'DataArea', 
@value = N'borger', 
@level0type = N'SCHEMA', @level0name = N'D220-10-21', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_AdresserMedDistrikter';
GO

