I am designing the persistence strategy for a data mart which consists of two facts tables and five dimension tables. This is based on the classic star schema design.
Each fact table contains a composite primary key comprised of each dimension table's single primary key. The elements of the fact table primary key is also a foreign key to each respective dimension table.
Initially, I was thinking that this would be a "one-to-many" relationship(one dimension to many facts). The problem I am having is, seeing that I have to persist the fact data after each dimension record is created because of the primary key dependencies, how is this accomplished in the mapping?
Any help is appreciated! DDL is listed below.
Mark
eg:
DDL for one of the facts tables: create table SalesFact { CompanyId INTEGER NOT NULL, TerritoryId INTEGER NOT NULL, SalesPersonId INTEGER NOT NULL, ProductId INTEGER NOT NULL, TimeId INTEGER NOT NULL, UnitsSold INTEGER, SaleAmt DECIMAL(10,2) PRIMARY KEY (CompanyId, TerritoryId, SalesPersonId, ProductId, TimeId), FOREIGN KEY (CompanyId) REFERENCES CompanyDimension(CompanyId) ON DELETE RESTRICT, FOREIGN KEY (TerritoryId) REFERENCES TerritoryDimension(TerritoryId) ON DELETE RESTRICT, FOREIGN KEY (SalesPersonId) REFERENCES SalesDimension(SalesPersonId) ON DELETE RESTRICT, FOREIGN KEY (ProductId) REFERENCES ProductDimension(ProductId) ON DELETE RESTRICT, FOREIGN KEY (TimeId) REFERENCES TimeDimension(TimeId) ON DELETE RESTRICT, }
DDL for the five dimension tables: create table CompanyDimension { CompanyId INTEGER NOT NULL PRIMARY KEY, Name VARCHAR(50), Type VARCHAR(20), ActiveCode TINYINT }
create table TerritoryDimension { RegionId INTEGER NOT NULL PRIMARY KEY, Name VARCHAR(50), ActiveCode TINYINT }
create table SalesDimension { SalesPersonId INTEGER NOT NULL PRIMARY KEY, Name VARCHAR(50), Level TINYINT, DateActive DATETIME, ActiveCode TINYINT }
create table ProductDimension { ProductId INTEGER NOT NULL PRIMARY KEY, Name VARCHAR(50), Category TINYINT, SubCategory TINYINT }
create table TimeDimension { TimeId INTEGER NOT NULL PRIMARY KEY, DayOfWeek DATETIME, DayOfMonth DATETIME, DayOfYear DATETIME, Month DATETIME, Quarter DATETIME, Year DATETIME, Holiday TINYINT, Weekend TINYINT }
_________________ "It shan't be played!" - Nigel Tufnel, 1982 - in reference to his vintage 1958 Les Paul Std
|