CREATE TABLE [D180-10-1].[DSAHIST_Skole_Institution](
  [INST_NR] [int] NULL,
  [INST_NAVN_FORK] [varchar](15) COLLATE Norwegian_100_CI_AS NULL,
  [POSTNR] [varchar](4) COLLATE Norwegian_100_CI_AS NULL,
  [INST_NAVN] [varchar](128) COLLATE Norwegian_100_CI_AS NULL,
  [CVR_NR] [varchar](8) COLLATE Norwegian_100_CI_AS NULL,
  [P_NR] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [INST_LEDER] [varchar](64) COLLATE Norwegian_100_CI_AS NULL,
  [TLF_NR] [varchar](9) COLLATE Norwegian_100_CI_AS NULL,
  [INST_ADR] [varchar](128) COLLATE Norwegian_100_CI_AS NULL,
  [VEJKODE] [varchar](4) COLLATE Norwegian_100_CI_AS NULL,
  [HUSNRBOGSTAV] [varchar](4) COLLATE Norwegian_100_CI_AS NULL,
  [POSTBOKS] [varchar](4) COLLATE Norwegian_100_CI_AS NULL,
  [ETAGE] [varchar](2) COLLATE Norwegian_100_CI_AS NULL,
  [DOERBETEGNELSE] [varchar](3) COLLATE Norwegian_100_CI_AS NULL,
  [AJOUR_DATO] [datetime2](3) NULL,
  [AJOUR_BRUGER] [varchar](30) COLLATE Norwegian_100_CI_AS NULL,
  [KOMMUNE_NR] [int] NULL,
  [KOMMUNE_NR_3] [int] NULL,
  [NEDLAGT_MND] [datetime2](3) NULL,
  [EJER_KODE] [int] NULL,
  [UNDERV_NIV] [int] NULL,
  [OPRETTET_MND] [varchar](6) COLLATE Norwegian_100_CI_AS NULL,
  [MIN_KODE] [int] NULL,
  [INST_TYPE_2] [int] NULL,
  [INST_TYPE_3] [int] NULL,
  [AKTIV_KODE] [varchar](1) COLLATE Norwegian_100_CI_AS NULL,
  [BEL_KOMMUNE] [int] NULL,
  [FLYTTE_KODE] [int] NULL,
  [FLYTTE_INST] [int] NULL,
  [HOVEDSKOLE_INST] [int] NULL,
  [E_MAIL] [varchar](80) COLLATE Norwegian_100_CI_AS NULL,
  [WEB_ADR] [varchar](80) COLLATE Norwegian_100_CI_AS NULL,
  [ENHEDSART] [int] NULL,
  [VEJNAVN] [varchar](40) COLLATE Norwegian_100_CI_AS NULL,
  [LOKALITET] [varchar](34) COLLATE Norwegian_100_CI_AS NULL,
  [STEDNAVN] [varchar](34) COLLATE Norwegian_100_CI_AS NULL,
  [GEO_BREDDE_GRAD] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [GEO_LAENGDE_GRAD] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [POSTDISTRIKT] [varchar](49) COLLATE Norwegian_100_CI_AS NULL,
  [BEL_REGION] [int] NULL,
  [REGION_NR] [int] 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([INST_NR],[INST_NAVN_FORK],[POSTNR],[INST_NAVN],[CVR_NR],[P_NR],[INST_LEDER],[TLF_NR],[INST_ADR],[VEJKODE],[HUSNRBOGSTAV],[POSTBOKS],[ETAGE],[DOERBETEGNELSE],[AJOUR_DATO],[AJOUR_BRUGER],[KOMMUNE_NR],[KOMMUNE_NR_3],[NEDLAGT_MND],[EJER_KODE],[UNDERV_NIV],[OPRETTET_MND],[MIN_KODE],[INST_TYPE_2],[INST_TYPE_3],[AKTIV_KODE],[BEL_KOMMUNE],[FLYTTE_KODE],[FLYTTE_INST],[HOVEDSKOLE_INST],[E_MAIL],[WEB_ADR],[ENHEDSART],[VEJNAVN],[LOKALITET],[STEDNAVN],[GEO_BREDDE_GRAD],[GEO_LAENGDE_GRAD],[POSTDISTRIKT],[BEL_REGION],[REGION_NR])),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_D180-10-1_DSAHIST_Skole_Institution] On [D180-10-1].[DSAHIST_Skole_Institution] (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'Hentet fra STIL via webservice til institutionsregisteret', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'INST_NR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'INST_NAVN_FORK';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'POSTNR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'INST_NAVN';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'CVR_NR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'P_NR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'INST_LEDER';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'TLF_NR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'INST_ADR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'VEJKODE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'HUSNRBOGSTAV';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'POSTBOKS';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'ETAGE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'DOERBETEGNELSE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'AJOUR_DATO';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'AJOUR_BRUGER';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'KOMMUNE_NR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'KOMMUNE_NR_3';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'NEDLAGT_MND';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'EJER_KODE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'UNDERV_NIV';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'OPRETTET_MND';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'MIN_KODE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'INST_TYPE_2';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'INST_TYPE_3';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'AKTIV_KODE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'BEL_KOMMUNE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'FLYTTE_KODE';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'FLYTTE_INST';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'HOVEDSKOLE_INST';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'E_MAIL';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'WEB_ADR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'ENHEDSART';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'VEJNAVN';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'LOKALITET';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'STEDNAVN';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'GEO_BREDDE_GRAD';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'GEO_LAENGDE_GRAD';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'POSTDISTRIKT';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution', 
@level2type = N'COLUMN', @level2name = N'BEL_REGION';
GO

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

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

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

EXEC sys.sp_addextendedproperty 
@name = N'DataArea', 
@value = N'skole', 
@level0type = N'SCHEMA', @level0name = N'D180-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_Skole_Institution';
GO

