CREATE TABLE [D060-14-5].[DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri](
  [PERIODE_AAR] [smallint] NULL,
  [PERIODE_MD] [smallint] NULL,
  [KOMNR] [smallint] NULL,
  [INST_ID] [int] NULL,
  [KALDINST] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [INSTITUTIONSNAVN] [varchar](100) COLLATE Norwegian_100_CI_AS NULL,
  [INSTITUTIONSTYPE] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [PASNINGSORDEN] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [SELVEJENDE] [varchar](3) COLLATE Norwegian_100_CI_AS NULL,
  [FRA_DATO] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [TIL_DATO] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [VEJNAVN] [varchar](52) COLLATE Norwegian_100_CI_AS NULL,
  [HUSNR] [varchar](52) COLLATE Norwegian_100_CI_AS NULL,
  [HUSBOGSTAV] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [ETAGE] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [SIDE] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [BYNAVN] [varchar](25) COLLATE Norwegian_100_CI_AS NULL,
  [POSTNR] [smallint] NULL,
  [INST_TLF] [varchar](16) COLLATE Norwegian_100_CI_AS NULL,
  [DAGINSTITUTIONS_NUMMER] [varchar](6) 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([PERIODE_AAR],[PERIODE_MD],[KOMNR],[INST_ID],[KALDINST],[INSTITUTIONSNAVN],[INSTITUTIONSTYPE],[PASNINGSORDEN],[SELVEJENDE],[FRA_DATO],[TIL_DATO],[VEJNAVN],[HUSNR],[HUSBOGSTAV],[ETAGE],[SIDE],[BYNAVN],[POSTNR],[INST_TLF],[DAGINSTITUTIONS_NUMMER])),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_D060-14-5_DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri] On [D060-14-5].[DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri] (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'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'PERIODE_AAR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'PERIODE_MD';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'KOMNR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'INST_ID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'KALDINST';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'INSTITUTIONSNAVN';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'INSTITUTIONSTYPE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'PASNINGSORDEN';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'SELVEJENDE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'FRA_DATO';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'TIL_DATO';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'VEJNAVN';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'HUSNR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'HUSBOGSTAV';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'ETAGE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'SIDE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'BYNAVN';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'POSTNR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'INST_TLF';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'DAGINSTITUTIONS_NUMMER';
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'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@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'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@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'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@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'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@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'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@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'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@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'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@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'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'SYS_Checksum';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'SysExecutionId', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'SYS_ExecutionId';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'SysDataDeliveryBatchIdCreate', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri', 
@level2type = N'COLUMN', @level2name = N'SYS_DataDeliveryBatchId_Create';
GO

EXEC sys.sp_addextendedproperty 
@name = N'DataArea', 
@value = N'dagtilbud', 
@level0type = N'SCHEMA', @level0name = N'D060-14-5', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_DT_DST_KMDi2_Institutionsregister_Etableri';
GO

