CREATE TABLE [D110-10-1].[DSAHIST_KMD_Elev_EleverPersonTemp](
  [GyldigFraDato] [datetime2](3) NULL,
  [GyldigTilDato] [datetime2](3) NULL,
  [Bopælskommune] [int] NULL,
  [BetalingskommuneFagsystem] [int] NULL,
  [FK_BetalingskommuneCPR_ID_Kommune] [int] NULL,
  [Klasseident] [int] NULL,
  [Elevident] [int] NULL,
  [Elevtype] [varchar](6) COLLATE Norwegian_100_CI_AS NULL,
  [cpr] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [Personlig_klassetrin] [int] NULL,
  [SkoleAar] [varchar](9) COLLATE Norwegian_100_CI_AS NULL,
  [BopælskommuneFraCPR] [int] NULL,
  [TosprogetElev] [varchar](20) COLLATE Norwegian_100_CI_AS NULL,
  [Skoledistrikt] [int] NULL,
  [DSA_BatchDate] [datetime2](3) 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([GyldigFraDato],[GyldigTilDato],[Bopælskommune],[BetalingskommuneFagsystem],[FK_BetalingskommuneCPR_ID_Kommune],[Klasseident],[Elevident],[Elevtype],[cpr],[Personlig_klassetrin],[SkoleAar],[BopælskommuneFraCPR],[TosprogetElev],[Skoledistrikt],[DSA_BatchDate])),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_D110-10-1_DSAHIST_KMD_Elev_EleverPersonTemp] On [D110-10-1].[DSAHIST_KMD_Elev_EleverPersonTemp] (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'Temp tabel til kombination af KMD og CPR data', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KMD_Elev_EleverPersonTemp';
GO

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

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

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KMD_Elev_EleverPersonTemp', 
@level2type = N'COLUMN', @level2name = N'Bopælskommune';
GO

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

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

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

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

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

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

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

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

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KMD_Elev_EleverPersonTemp', 
@level2type = N'COLUMN', @level2name = N'BopælskommuneFraCPR';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'1 = tosproget\n0 = ikke-tosproget', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KMD_Elev_EleverPersonTemp', 
@level2type = N'COLUMN', @level2name = N'TosprogetElev';
GO

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

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

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

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

EXEC sys.sp_addextendedproperty 
@name = N'DataArea', 
@value = N'generel', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_KMD_Elev_EleverPersonTemp';
GO

