Database design 维度表中的复合主键

Database design 维度表中的复合主键,database-design,data-warehouse,business-intelligence,Database Design,Data Warehouse,Business Intelligence,我有一个带有复合主键的维度表,例如: 操作员: centre registreDuCommerce libelleCentre LibelleRegistreduCommerce col1 col2 col3 centre registreDuCommerce 主键是:center,registerReduceCommerce 事实表是 MyFactTable: centre registreDuCommerce libelleCentre LibelleRegistreduCommerc

我有一个带有复合主键的维度表,例如:

操作员

centre
registreDuCommerce
libelleCentre
LibelleRegistreduCommerce
col1
col2
col3
centre 
registreDuCommerce
主键是:
center,registerReduceCommerce

事实表是

MyFactTable

centre
registreDuCommerce
libelleCentre
LibelleRegistreduCommerce
col1
col2
col3
centre 
registreDuCommerce
中心和注册商??中心:是城市的代码 公司的安装地点注册商:公司的标识 公司

这些键有助于识别一家公司,因为我们可以使用不同的ce对相同的
RegistryReduceCommerce
进行罚款

解决这个问题有任何原因,因为我发现在维度表中不可能有复合主键


感谢

这样的复合主键不仅不常见,而且非合成主键也不常见(可能除了date)。整数将是一个更为传统的主键——您仍然可以在这些列上放置一个非空且唯一的键

所以事实表应该由维度表的整数外键以及度量组成

create table dim_customer (
  id         integer primary key,
  first_name character,
  ...

create table dim_item (
  id           integer primary key,
  product_code character unique,
  ...


create table fct_sales (
  item_id     references dim_item(id),
  customer_id references dim_customer(id),
  ...
  sale_amount number
当原始数据与产品代码一起到达时,您可以在dim_item表中插入一个唯一的列表,其中包含所有不存在的产品代码

然后加载事实表时,从dim_项目表中查找项目的相关id,并将该值插入fct_销售表中


当您查询从事实表连接到维度表的仓库以获得有意义的值(客户名称、项目代码等)时。

但是在datawarhouse建模中,我们应该将主键作为一列,而不是复合主键Yes。“一个整数将是一个更为传统的主键”。我们可以用像id_CERC这样的东西作为主键来表示复合主键吗?但是我们如何在事实表中引用它呢?当您加载(center和registreduceommerc)时,您会看到它是否已经在维度表中。如果是,则读取它的唯一id号,并在事实表中使用该id号。如果不是,则插入它们,读取新生成的唯一id,并在事实表中使用该id。事实表中的外键列都应该是整数,用于标识相关维度表中的行。Kimball有很多很棒的文章——不幸的是,目前你还缺乏对基本概念和词汇的理解。