具有相同结构的操作数据库可在多个国家/地区使用。生成跨多个数据库唯一的主键
country A has table Users with column user_id
country B has table Users with column user_id
country C has table Users with column user_id
当从所有三个数据库中的数据被带至暂存区用于进一步数据仓库目的的所有三个业务表被集成到具有dwh_user_id单个表的用户。
逻辑看起来像下面:
if record comes from A then dwh_user_id = 1000000 + user_id
if record comes from B then dwh_user_id = 4000000 + user_id
if record comes from c then dwh_user_id = 8000000 + user_id
我有一个强烈的感觉,这是一个非常糟糕的做法。什么是更好的方法? (user_id + country_iso_code也许?)
我会添加两列:国家和一个新的唯一ID。 –
你在说什么是Master Data Management。 'CountryCode + to_char(user_id)'是一种方法。虽然对使用字符串主键有多重意见。另一种方式是可以使用代理键作为DWH_USER_ID并添加2列,一列用于国家代码,另一列用于user_id。 – Utsav
任何固定长度的键都会有这种感觉,即分配的范围不够,记录会溢出到下一个范围。您可以决定数据库中是否存在这种可能性,如果是这样,您可以增加范围直到感觉良好,或者使用带有分隔符的可变长度键。 – GSerg