SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Foreign key constraints in data warehouses


Foreign key constraints in data warehouses

Author
Message
wildh
wildh
SSC-Addicted
SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)

Group: General Forum Members
Points: 418 Visits: 675
I'd love to be in Hendra's position...... a datawarehouse that isnt mission critical. What a joy that would be. We have several real time cubes that make our datawarehouse mission critical, not just for the users but they feed information back to the OLTP (OK, not the best scenario I know but the decision was taken out of my hands). With that in mind FK's have proved a their worth on a couple of ocassions. I'm not overly keen on them as they do prove a bit of a pain when developing and other things but they have proved useful in our situation. On several other projects in the same datawarehouse I have elected to remove FK's because I deemed them unnecessary, so I suppose my approach is horses for courses, what works in one case might not in another.



Hommer
Hommer
SSC Veteran
SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)

Group: General Forum Members
Points: 226 Visits: 251
Let's stick with Kimball mathod for a minute.

These PK/Fk pairs are surrogate keys not the natural keys from OLTP. They should be built during initial OLAP load and maintained in the subsequent ETL process.

Which means in dimensional table, if it is type2, it gets a new set of PK with every update. Thus, comes with the need of remapping the fact table's FK to that new FK.

Now, to implement this theory in SSIS successfully is something I would like to see.

Anybody has the experiece implementing, say 3 to 5 fact tables with a dozen dimention tables and the total size of the db is in 100 GB range?

How long will a historical load take?
RonKyle
RonKyle
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2768 Visits: 3501
These PK/Fk pairs are surrogate keys not the natural keys from OLTP. They should be built during initial OLAP load and maintained in the subsequent ETL process.


Maybe I should have been clearer from my earlier entries that these are the FKs I'm using. The former PKs may be unique indexed, but all the dimension data is turned into a surrogate key integer, even if the original PK was an integer. I would not advocate trying to maintain the OLTP PK/FK relationship.



RBarryYoung
RBarryYoung
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14902 Visits: 9518
hongchen91 (3/11/2008)
Anybody has the experiece implementing, say 3 to 5 fact tables with a dozen dimention tables and the total size of the db is in 100 GB range?

How long will a historical load take?


This is highly dependent on the environment & configuration, however in my experience, 3 hours would be the absolute minimum, and I have certainly had to wiat over 2 weeks for some to complete.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Kerry Bennett-335592
Kerry Bennett-335592
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 58
I always declare fact to dimension foreign key constrains in SQL Server 2005.
However I do not enforce the foreign key constraint, nor define any cascading event actions.
Example :
ALTER TABLE
[dm].[Fact_Episode_Summary] WITH NOCHECK ADD CONSTRAINT
[FK_Fact_Episode_Summary_Dim_Hospital] FOREIGN KEY([Hospital_DID])
REFERENCES [dm].[Dim_Hospital] ([Hospital_DID]) NOT FOR REPLICATION
GO
ALTER TABLE [dm].[Fact_Episode_Summary] NOCHECK CONSTRAINT
[FK_Fact_Episode_Summary_Dim_Hospital]
GO

I, like other noted here , do not enforce the constraint as the ETL process swill always gurantee that the relationship is valid. To do so would be an unnecessary overhead.

However the relationship is very important to the query optimiser. It tells the optimiser that it can rely on the 1:n relationship. For very large databases this is critical as it allows the qury optimser to design a suitable parrallel query plan.

I have been building data warehouses for about 10 years now.
RonKyle
RonKyle
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2768 Visits: 3501
That's an interesting idea with the NOCHECK constraint. Doing that will allow you to take advantage of 2005s ability to file non conforming ones to a type of UNKNOWN bucket.

I still would be inclined to leave it on in the beginning and after major changes to catch errors in the transformation and load portion (as I said in a previous post, except for that I would not have caught a load error) although I supposed once committed to the UNKNOW bucket there'd be nothing more to do about it.



RBarryYoung
RBarryYoung
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14902 Visits: 9518
Kerry Bennett (3/11/2008)
I always declare fact to dimension foreign key constrains in SQL Server 2005.
However I do not enforce the foreign key constraint, nor define any cascading event actions.

I have not tried this, but I think that I would be OK with it.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Lynn Pettis
Lynn Pettis
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39754 Visits: 38563
Which means in dimensional table, if it is type2, it gets a new set of PK with every update. Thus, comes with the need of remapping the fact table's FK to that new FK.


Okay, I'm lost here. Why would you have to remap the PK/FK relationship if you entered a new record in the dimension table to the fact table? The value of the PK has changed, not the PK/FK relationship.

Cool

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Hommer
Hommer
SSC Veteran
SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)

Group: General Forum Members
Points: 226 Visits: 251
Pk on the dim table has changed to a new value. Its counter part in the fact FK needs to reset to that value. That is what I meant "remap".
Lynn Pettis
Lynn Pettis
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39754 Visits: 38563
But that doesn't change the PK/FK relationship.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search