Kevin6


I must be missing something somewhere...

I have a simple table with three fields: ID, LastName, FirstName. The ID is defined as the PK. In the table is a record of "12345, Smith, John". The incoming flat file has a record of "12345, Smith, Johnny".

In the SCD transform, the ID is the business key, and Last Name and First Name are defined as historical attributes.

During the load, the SCD transform correctly sends the data down the right path, but the insert fails with a primary key violation - as I would expect since it's trying to create a new current record.

How do I get around this problem without removing the PK

thx




Re: using historical attributes with SCD transform on a table with a PK

Phil Brammer


You're going to need more fields in that table to make it work...

Where is your current record indicator (either start and end date fields or a current indicator field)

And ID shouldn't be the PK of the table as that is the business key, designed not to change. You should have a separate PK field in that table -- either an (gasp!) identity field, or a self-generated surrogate key field.

This allows for the business key to never change (it shouldn't!), but still allows for new records to be inserted because the business key isn't part of the table's primary key constraint.






Re: using historical attributes with SCD transform on a table with a PK

desibull

Phil:

What about date fields such as an Effective Start Date and and Effective End Date to capture the valid timespan for a record






Re: using historical attributes with SCD transform on a table with a PK

Phil Brammer

desibull wrote:

Phil:

What about date fields such as an Effective Start Date and and Effective End Date to capture the valid timespan for a record



What about them I suggested them in my post above.





Re: using historical attributes with SCD transform on a table with a PK

desibull

My apologies - should have read your post more closely





Re: using historical attributes with SCD transform on a table with a PK

Kevin6

Phil, thanks for the info. I forgot to include the SCD indicator field in my original post.

Well, 6 hours later and here's what I have in this customers table: ID, Lastname, Firstname, SCD_Indicator, SurrogateKey where SurrogateKey is an IDENT (gasp) PK field, ID is defined as a fixed attribute in the SCD transform and Lastname/Firstname are historical.

The SCD transform is happy with this arrangement and changes to Lastname/FirstName are stored as new records with a status of 'current' (and the old record as 'expired').

But...

This table owns another table (Addresses), i.e. there is a one-to-many relationship between the customers table and the Addresses table, with the SurrogateKey implanted in the Addresses table as the foreign key to the customers table.

Storing new records in the parent table (i.e. new 'current' records) does not obviously update the child (addresses) table with the new record surrogate key ident value - so how do I update the child table to use the new parent record with the changed historical attributes

thanks again





Re: using historical attributes with SCD transform on a table with a PK

Phil Brammer

ID should be defined as a business key

SCD should not be part of the attributes either.






Re: using historical attributes with SCD transform on a table with a PK

jwelch

Kevin6 wrote:

This table owns another table (Addresses), i.e. there is a one-to-many relationship between the customers table and the Addresses table, with the SurrogateKey implanted in the Addresses table as the foreign key to the customers table.

Storing new records in the parent table (i.e. new 'current' records) does not obviously update the child (addresses) table with the new record surrogate key ident value - so how do I update the child table to use the new parent record with the changed historical attributes

You could use an Execute SQL task after your dataflow to issue a batch update.

However, it is a bit unusual to model an SCD type 2 this way (at least in my experience). This sounds more like a normalized model. If I'm understanding correctly, you are tracking history in the customer table, but not in the address Why not just relate the address directly in the fact






Re: using historical attributes with SCD transform on a table with a PK

Kevin6

True enough, it is more of a normalized model. And I will be tracking history in the addresses table as well.

I didn't design it, I just have to make it work. :-)

thx to all