Use the surrogate key

  • Here is the scenario. I have a fact table that looks like the following:

    factEmployeeWorkHours

    PK ID

    LastName

    FirstName

    Hours

    The fact table joins to a dimension table that looks like the following:

    dimOrganization

    PK ID

    EmployeeLastName

    EmployeeFirstName

    Store

    StoreManager

    RegionalManager

    VP

    Region

    State

    But there is a problem. The Employee can be assigned to more than one store and therefore can have more than one store manager, region, etc. If I join the fact table to the dim table during ETL to get the surrogate key/PK from the dim table, I will have multiple PKs per fact table row. I know that Kimball wants to have an FK in the fact table that joins the PK in the dimension table, but is that prudent in this case?

  • imani_technology (11/5/2012)


    Here is the scenario. I have a fact table that looks like the following:

    factEmployeeWorkHours

    PK ID

    LastName

    FirstName

    Hours

    The fact table joins to a dimension table that looks like the following:

    dimOrganization

    PK ID

    EmployeeLastName

    EmployeeFirstName

    Store

    StoreManager

    RegionalManager

    VP

    Region

    State

    But there is a problem. The Employee can be assigned to more than one store and therefore can have more than one store manager, region, etc. If I join the fact table to the dim table during ETL to get the surrogate key/PK from the dim table, I will have multiple PKs per fact table row. I know that Kimball wants to have an FK in the fact table that joins the PK in the dimension table, but is that prudent in this case?

    It all comes down to granularity.

    If business requirements call for collecting the employee hours not matter where the employee was working then you shouldn't care about different stores, different managers, etc.

    If business requirements call for collecting detailed information about where and with who the employee was working then the design lacks much needed columns to go down to such granularity.

    Either way, the design of the fact table (for starters) looks a bit fuzzy to me. Either that fact table expects to have a single row per employee which is the same as saying that the table is not a fact table but a summary table OR, table expects to store as many rows as needed for employee so to track where the employee has worked... in this case having the name of the employee on each row is really not a good idea.

    Would you please give more details?

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • imani_technology (11/5/2012)


    Here is the scenario. I have a fact table that looks like the following:

    factEmployeeWorkHours

    PK ID

    LastName

    FirstName

    Hours

    Is there a reason why you don't have an employee dimension? That way on your fact table, you could have two dimensions (one for employee, one for store), and employees could work quite happily across multiple stores without it being problematic.

    You would end up with a structure on your fact table such as:

    factEmployeeWorkHours

    PK ID

    Employee Dimension Key

    Store Dimension Key

    Hours

    There's a common misconception that dimensional data warehouses are not normalised. While there is some truth in that, it's better to think of them as denormalised in specific cases. In general, fact tables are heavily normalised. That means that if you have repeated sequences within a fact table, the chances are you are missing a dimension.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply