CREATE TABLE [D180-11-1].[DSAHIST_KVARAPPOVERG](
  [SkoleårAfgang] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [AfdelingAfgang] [varchar](200) COLLATE Norwegian_100_CI_AS NULL,
  [AfdelingsBeliggenhedskommunenummerAfgang] [int] NULL,
  [AfdelingsnummerAfgang] [int] NULL,
  [AfdelingstypeAfgang] [varchar](200) COLLATE Norwegian_100_CI_AS NULL,
  [InstitutionAfgang] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [InstitutionsnummerAfgang] [int] NULL,
  [Statustidspunkt] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [MellemgruppeAfgang] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [UddannelsesgruppeStatus] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [AntalElever] [bigint] NULL,
  [AndelElever] [varchar](10) 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([SkoleårAfgang],[AfdelingAfgang],[AfdelingsBeliggenhedskommunenummerAfgang],[AfdelingsnummerAfgang],[AfdelingstypeAfgang],[InstitutionAfgang],[InstitutionsnummerAfgang],[Statustidspunkt],[MellemgruppeAfgang],[UddannelsesgruppeStatus],[AntalElever],[AndelElever])),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-11-1_DSAHIST_KVARAPPOVERG] On [D180-11-1].[DSAHIST_KVARAPPOVERG] (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 API', 
@level0type = N'SCHEMA', @level0name = N'D180-11-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KVARAPPOVERG';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D180-11-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KVARAPPOVERG', 
@level2type = N'COLUMN', @level2name = N'SkoleårAfgang';
GO

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

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

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

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

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

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

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

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

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

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

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

