I always keep Type 0, 1 and 2 in one table.
I also treat Type 0-s and Type 1-s the same, and Type 2-s the other way.
- Type 1/0 changes lead to updating all versions in the SCD table for the same business/natural ID to reflect the new info.
- Type 2 changes lead to updating the newest row in the SCD table to contain the new change date as the valid-to date, and the current-indicator to contain FALSE, and a new row with the new data,valid-from as the change date, valid-to to '9999-12-31'.
With this type of staging data:
CREATE TABLE stg_customer (
cust_id INT NOT NULL -- natural identifier
,cust_chg_dt DATE -- change date
,cust_first_name VARCHAR(30) -- type 1
,cust_last_name VARCHAR(30) -- type 1
,cust_phoneno VARCHAR(30) -- type 1
,cust_loyalty_lvl INT -- type 2
,cust_org_id INT -- type 2
) ;
... my SCD table looks like so:
CREATE TABLE dim_customer_scd (
cust_key BIGINT
DEFAULT dim_customer_scd_seq.NEXTVAL NOT NULL -- surrogate key, primary key
, cust_id BIGINT NOT NULL -- natural identifier
, cust_from_dt DATE NOT NULL -- effective begin date
, cust_to_dt DATE NOT NULL -- effective end date
, cust_is_current BOOLEAN
DEFAULT(cust_to_dt='9999-12-31') NOT NULL -- current indicator
, cust_cre_ts TIMESTAMP(0) NOT NULL -- created timestamp
, cust_udt_ts TIMESTAMP(0) NOT NULL -- updated timestamp
, cust_first_name VARCHAR(30) -- Type 1 column
, cust_last_name VARCHAR(30) -- Type 1 column
, cust_phoneno VARCHAR(30) -- Type 1 column
, cust_loyalty_lvl INT -- Type 2 column
, cust_org_id INT -- Type 2 column
)
;