CREATE TABLE [D110-10-1].[DSAHIST_OpusKontoplanEDW](
  [OpusKontoplanID] [bigint] NULL,
  [ZIFUNKT] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [ZIGRUPP] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [ZIEJERFH] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [ZIART_IM] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [ZIDRANST] [varchar](10) COLLATE Norwegian_100_CI_AS NULL,
  [ZIASTE_IM] [int] NULL,
  [CMMT_ITEM0] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [PU_MEASURE0] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [COSTELMNT0] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [FUNDS_CTR0] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [FUND0] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [COSTCENTER0] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [PROFIT_CTR0] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [WBS_ELEMT0] [varchar](50) COLLATE Norwegian_100_CI_AS NULL,
  [FK_Kommune_ID_Kommune] [bigint] NULL,
  [FK_OpusArtskontoHierarki_ID_OpusArtskontoHierarkiI] [bigint] NULL,
  [FK_OpusBevillingsansvarsstedHierarki_ID_OpusBevill] [bigint] NULL,
  [FK_OpusKapitalmiddelHierarki_ID_OpusKapitalmiddelH] [bigint] NULL,
  [FK_OpusOmkostningsstedHierarki_ID_OpusOmkostningss] [bigint] NULL,
  [FK_OpusProfitcenterHierarki_ID_OpusProfitcenterHie] [bigint] NULL,
  [FK_OpusElementHierarki_ID_OpusProjektstrukturplane] [bigint] 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([OpusKontoplanID],[ZIFUNKT],[ZIGRUPP],[ZIEJERFH],[ZIART_IM],[ZIDRANST],[ZIASTE_IM],[CMMT_ITEM0],[PU_MEASURE0],[COSTELMNT0],[FUNDS_CTR0],[FUND0],[COSTCENTER0],[PROFIT_CTR0],[WBS_ELEMT0],[FK_Kommune_ID_Kommune],[FK_OpusArtskontoHierarki_ID_OpusArtskontoHierarkiI],[FK_OpusBevillingsansvarsstedHierarki_ID_OpusBevill],[FK_OpusKapitalmiddelHierarki_ID_OpusKapitalmiddelH],[FK_OpusOmkostningsstedHierarki_ID_OpusOmkostningss],[FK_OpusProfitcenterHierarki_ID_OpusProfitcenterHie],[FK_OpusElementHierarki_ID_OpusProjektstrukturplane])),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_OpusKontoplanEDW] On [D110-10-1].[DSAHIST_OpusKontoplanEDW] (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'Tabel med indlæste OPUS kontoplaner (EDW)', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Surrogatnøgle', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'OpusKontoplanID';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Værdi for Funktion', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'ZIFUNKT';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Værdi for Gruppering', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'ZIGRUPP';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Værdi for Ejerforhold', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'ZIEJERFH';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Værdi for Art', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'ZIART_IM';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Værdi for Dranst', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'ZIDRANST';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Værdi for Sted', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'ZIASTE_IM';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Værdi for Bevillingsposition', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'CMMT_ITEM0';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Værdi for Bevillingsprogram', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'PU_MEASURE0';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Hierarkiværdi for Artskonto', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'COSTELMNT0';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Hierarkiværdi for Bevillingsansvarssted', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'FUNDS_CTR0';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Hierarkiværdi for Kapitalmiddel', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'FUND0';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Hierarkiværdi for Omkostningssted', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'COSTCENTER0';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Hierarkiværdi for Profitcenter', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'PROFIT_CTR0';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Hierarkiværdi for Projektstrukturplanelement', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'WBS_ELEMT0';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Foreign key til Kommunetabellen', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'FK_Kommune_ID_Kommune';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Foreign key til Opus artskontohierarkitabellen', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'FK_OpusArtskontoHierarki_ID_OpusArtskontoHierarkiI';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Foreign key til Opus bevillingsansvarsstedhierarkitabellen', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'FK_OpusBevillingsansvarsstedHierarki_ID_OpusBevill';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Foreign key til Opus kapitalmiddelhierarkitabellen', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'FK_OpusKapitalmiddelHierarki_ID_OpusKapitalmiddelH';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Foreign key til Opus omkostningsstedhierarkitabellen', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'FK_OpusOmkostningsstedHierarki_ID_OpusOmkostningss';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Foreign key til Opus profitcenterhierarkitabellen', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'FK_OpusProfitcenterHierarki_ID_OpusProfitcenterHie';
GO

EXEC sys.sp_addextendedproperty 
@name = N'MS_Description', 
@value = N'Foreign key til Opus projektstrukturplanelementhierarkitabellen', 
@level0type = N'SCHEMA', @level0name = N'D110-10-1', 
@level1type = N'TABLE',  @level1name = N'DSAHIST_OpusKontoplanEDW', 
@level2type = N'COLUMN', @level2name = N'FK_OpusElementHierarki_ID_OpusProjektstrukturplane';
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_OpusKontoplanEDW', 
@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_OpusKontoplanEDW', 
@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_OpusKontoplanEDW', 
@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_OpusKontoplanEDW', 
@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_OpusKontoplanEDW', 
@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_OpusKontoplanEDW', 
@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_OpusKontoplanEDW', 
@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_OpusKontoplanEDW', 
@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_OpusKontoplanEDW', 
@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_OpusKontoplanEDW', 
@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_OpusKontoplanEDW';
GO

