0

I'm trying to build a Star Schema in MySQL. I have the raw data, and I've uild the Dimension Tales and Fact Table. But it looks like my Fact Table is linking correctly to the Dimension Table, because all the Foreign Key values are NULL.

How do I get my fact.producerFK column to show the foreign key values, instead of NULL?

I've built the Dimension Table....

create table producer (
ProducerKey int not null auto_increment primary Key,
ProducerName text);

I populated it with distinct values....

Insert into producer (ProducerName)
Select distinct Producer from tracker;

and created the Fact Table, with a foreign key referencing the producer table....

create table fact (
FactID int not null auto_increment Primary Key,
Total_Commission int not null,
ProducerFK int,
foreign Key(ProducerFK) references Producer(producerkey)
);

I populated the fact table....

insert into fact (Total_Commission)
select `Total Commission` from tracker
;

I was expecting to see the fact.producerFK column to show the foreign key values instead of NULL. How do I fix this?

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • FKs are mainly for referntial integrity , they don't push or pull data. – P.Salmon Apr 12 '23 at 08:58
  • 1
    You need to insert the correct key value into fact.ProducerFK for each record. Your system cannot magically know which producer record to associate with each fact record – NickW Apr 12 '23 at 16:30

0 Answers0