ETL Processing Mechanics of ETL
The Flow Source File Extract Transform Transformed File Extract Generate Key Presentation Mart Surrogate Keys
The Flow Customer Extract Transform Transformed File CopyCustomer Generate Key Presentation Mart NewTable
Extract Customer data into a working table SELECT * INTO SalesCopy FROM Sales;
Add Surrogate Keys Create a table with primary key and surrogate key attributes, transaction primary key as primary key and autoincrement for a new surrogate key
Create a Surrogate Key Table create table surrogate ( keyval int constraint pk primary key, Autokey int identity(1,1), Surrogate int)
Insert primary keys into the surrogate key table and generate surrogate keys. INSERT INTO Surrogate (KeyVal) SELECT KeyVal FROM Sales WHERE KeyVal NOT IN (SELECT KeyVal FROM Surrogate);
Copy the autonumber field into an integer field. UPDATE Surrogate SET Surrogate= autokey WHERE surrogate is null
Add a CustomerKey column to the CustomerCopy table ALTER TABLE Sales ADD SalesKey Int;
Update the CustomerCopy table to add surrogate keys. UPDATE sales SET sales.saleskey = surrogate.surrogate FROM sales, surrogate WHERE sales.keyval = surrogate.keyval
Drop unnecessary columns ALTER TABLE CustomerCopy DROP balance;