Search code examples
oracle-databasedata-warehousedimensional-modelingstar-schema

Dimensional data warehouse customer with multiple accounts


I'm designing and building a sales fact table in a star schema and I can't seem to work out how to go about the following problem:

A customer can have 1 or 2 accounts, but an account can only belong to 1 customer. So this is a 1 to many relationship.

Should I create dimensions for customer and account, and link them with a bridge table?

In the final fact table I would have as example rows:

| date_id | cust_id | Acc_id | count(sales) |  
|    1    |    150  |   25   |      1       |  
|    1    |    150  |   26   |      1       |    

Solution

  • Simply make the Account and Customer Dimensions. Do not link them with a foreign key - that's how you'd do things if you were creating a fully normalized schema, rather than a Star schema. The link between Customer and Account is held in the Fact table(s) - because you have a row of data holding Cust_Id 150 alongside Acc_Id 25 and another row of data holding the same Cust_Id against Acc_Id 26, it will be apparent in any OLAP layer you build over it that these are related.

    Note that you could also simply have an Account Dimension, and hold the Customer's details as attributes on the Account. Without knowing the rest of your model it's impossible to tell whether this is a more suitable solution, though.