Bridge table
A table that sits between a fact table and a dimension when one fact row relates to several rows of that dimension, such as a sale credited to two sales reps. It holds one row per member of each group, often with a weighting factor that splits the measure among them.
Also: bridge tables · multivalued dimension bridge · many-to-many bridge table
On this page · 7 sections
- Category
- Data modeling
- Also known as
- bridge tables, multivalued dimension bridge, many-to-many bridge table
- Goes deeper in
- Data Modeling
A bridge table resolves a many-to-many relationship between facts and a dimension. Normally each fact row has exactly one value per dimension: one customer, one product, one date. Some dimensions are legitimately multivalued. A hospital visit can carry several diagnoses, a bank account can have several owners, and a sale can be shared by several reps. One foreign key cannot point to all of them.
In Ralph Kimball's design the fact row stores a group key. The bridge table has one row for each member of that group, pairing the group key with a dimension key, so a group of three reps is three bridge rows. A weighting factor column can be added to each row, with the factors in a group adding up to 1, to allocate the fact's measures across the members.
Outside dimensional modeling, bridge table is often used for any table that links two others many-to-many, which database designers also call a junction or associative table. Kimball's usage is narrower: the structure for a multivalued dimension, plus a specially built bridge for ragged hierarchies, whose branches vary in depth. When group membership changes over time, the bridge rows also need effective and expiration dates.
create table bridge_rep_groups (
rep_group_key integer not null, -- the key stored on the fact row
rep_key integer not null, -- joins to dim_sales_reps
weighting_factor numeric(5, 4) not null, -- adds up to 1 within a group
primary key (rep_group_key, rep_key)
);
select
r.rep_name,
sum(f.sale_amount) as unweighted_amount,
sum(f.sale_amount * b.weighting_factor) as weighted_amount
from fct_sales f
join bridge_rep_groups b on b.rep_group_key = f.rep_group_key
join dim_sales_reps r on r.rep_key = b.rep_key
group by r.rep_name
order by r.rep_name;A join through a bridge repeats the fact row once per group member. Summing a measure after that join counts a shared sale in full for every rep, and the grand total exceeds real sales. The weighting factor is what makes the total come out right.
Both answers are useful and they are different. Unweighted, the query says how much business each rep took part in. Weighted, it says how much each rep is credited with. A report has to state which one it shows.
- Summing a measure across the bridge without a weighting factor and presenting the result as a total. Each member's figure is valid by itself; the sum of them is not.
- Weights that do not add up to 1 within a group, which loses or invents revenue. A test that sums the weighting factor per group key catches it.
- Reaching for a bridge when a simpler design would serve. Changing the grain to one row per rep per sale, or naming a primary rep, avoids the bridge and the harder queries that come with it.
- What is the difference between a bridge table and a junction table?
- Structurally they are the same thing: a table of key pairs that resolves a many-to-many relationship. Junction table is the general database term. In dimensional modeling, bridge table means specifically the table between a fact table and a multivalued dimension, usually keyed by a group, and it may carry a weighting factor that a plain junction table has no need for.
- What is a weighting factor in a bridge table?
- It is a number on each bridge row that says what share of the fact belongs to that member, such as 0.5 each for two reps who split a sale. The factors for one group add up to 1. Multiplying a measure by the factor before summing allocates it, so the members' figures add back to the true total.
- When should you use a bridge table?
- Use one when a fact row can relate to an open-ended number of values in one dimension and the business needs to analyze by each of them: diagnoses per visit, owners per account, skills per employee. If the number of values is small and fixed, or one of them is clearly primary, separate columns or a single primary key are easier to query.
