Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««1234»»»

Foreign key constraints in data warehouses Expand / Collapse
Author
Message
Posted Tuesday, March 11, 2008 2:35 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, July 21, 2014 3:49 AM
Points: 292, Visits: 661
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.


Post #467229
Posted Tuesday, March 11, 2008 7:41 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 9:49 AM
Points: 166, Visits: 184
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?
Post #467392
Posted Tuesday, March 11, 2008 8:00 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: 2 days ago @ 3:40 PM
Points: 804, Visits: 1,990
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.



Post #467420
Posted Tuesday, March 11, 2008 9:25 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, June 5, 2014 10:54 AM
Points: 9,902, Visits: 9,480
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."
Post #467884
Posted Tuesday, March 11, 2008 11:39 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, September 29, 2013 7:30 PM
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.
Post #467906
Posted Wednesday, March 12, 2008 8:16 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: 2 days ago @ 3:40 PM
Points: 804, Visits: 1,990
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.



Post #468127
Posted Wednesday, March 12, 2008 1:02 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, June 5, 2014 10:54 AM
Points: 9,902, Visits: 9,480
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."
Post #468340
Posted Wednesday, March 12, 2008 1:21 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 5:09 PM
Points: 23,089, Visits: 31,635
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.




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)
Post #468359
Posted Wednesday, March 12, 2008 1:59 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 9:49 AM
Points: 166, Visits: 184
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".
Post #468372
Posted Wednesday, March 12, 2008 2:09 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 5:09 PM
Points: 23,089, Visits: 31,635
But that doesn't change the PK/FK relationship.


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)
Post #468378
« Prev Topic | Next Topic »

Add to briefcase ««1234»»»

Permissions Expand / Collapse