简体   繁体   English

向数据仓库添加新维度(向事实表添加新列)

[英]Adding new dimensions to data warehouse (adding new columns to fact table)

I am building an OLAP database and am running into some difficulty. 我正在构建OLAP数据库,遇到了一些困难。 I have already setup a fact table that includes columns for sales data, like quantity, sales, cost, profit, etc. The current dimensions I have are Date, Location, and Product. 我已经设置了一个事实表,其中包含用于销售数据的列,例如数量,销售,成本,利润等。我当前拥有的维是日期,位置和产品。 This means I have the foreign key columns for these dimension tables included in the fact table as well. 这意味着我在事实表中也包含了这些维表的外键列。 I have loaded the fact table with this data. 我已经用这个数据加载了事实表。

I am now trying to add a dimension for salesperson. 我现在正在尝试为销售人员添加维度。 I have created the dimension, which has the salesperson's ID and their name and location. 我创建了维度,其中包含销售人员的ID以及他们的姓名和位置。 However, I can't edit the fact table to add the new column that will act as a foreign key to the salesperson dimension. 但是,我无法编辑事实表以添加新列,该新列将充当销售人员维度的外键。

I want to use SSIS to do this, by using a look up on the sales database which the fact table is based on, and the salesperson ID, but I first need to add the Salesperson column to my fact table. 我想通过查找事实表所基于的销售数据库以及销售员ID来使用SSIS来执行此操作,但是我首先需要将Salesperson列添加到我的事实表中。 When I try to do it, I get an error saying that it can't create a new column because it will be populated with NULLs. 当我尝试执行此操作时,出现一条错误消息,提示它无法创建新列,因为它将填充为NULL。

I'm going to take a guess as to the problem you're having, but this is just a guess: your question is a little difficult to understand. 我将对您遇到的问题进行猜测,但这只是一个猜测:您的问题有点难以理解。

I'm going to make the assumption that you have created a Fact table with x columns, including links to the Date, Location, and Product dimensions. 我将假设您已经创建了一个包含x列的Fact表,包括到Date,Location和Product维度的链接。 You have then loaded that fact table with data. 然后,您已在事实表中加载了数据。

You are now trying to add a new column, SalesPerson_SK (or ID), to that table. 现在,您正在尝试向该表添加新列SalesPerson_SK(或ID)。 You do not wish to allow NULL values in the database, so you clear the 'allow NULL' checkbox. 您不希望在数据库中允许使用NULL值,因此请清除“ allow NULL”复选框。 However, when you attempt to save your work, the table errors out with the objection that it cannot insert NULL into the SalesPerson_SK column. 但是,当您尝试保存工作时,该表会出错,因为它无法将NULL插入SalesPerson_SK列。

There are a few ways around this limitation. 有几种方法可以解决此限制。 One, which is probably the best if you are still in the development stage, is to issue the following command: 如果您仍处于开发阶段,则可能是最好的一种方法是发出以下命令:

TRUNCATE TABLE dbo.FactMyFact

which will remove all data from the table, allowing you to make your changes and reload the table with the new column included. 它将删除表格中的所有数据,使您可以进行更改,并使用包含新列的表格重新加载表格。

If, for some reason, you cannot do so, you can alter the table to add the column but include a default constraint that will put a default value into your fact table , essentially a dummy record that says, "I don't know what this is" 如果由于某种原因而不能这样做,则可以更改表以添加列,但可以包括一个默认约束 ,该约束将把默认值放入事实表中 ,本质上是一个虚拟记录,上面写着:“我不知道这是”

ALTER TABLE FactMyFact
ADD Salesperson_SK INT NOT NULL 
CONSTRAINT DF_FactMyFact_SalesPersonSK DEFAULT 0

If you do not wish to put a default value into the table, simply create the column and allow NULL values, either by checking the box on the design page or by issuing the following command: 如果您不希望在表中输入默认值,只需创建该列并允许NULL值,方法是选中设计页面上的复选框或发出以下命令:

ALTER TABLE FactMyFact
ADD Salesperson_SK INT NULL 

This answer has been given based on what I think your problem is: let me know if it helps. 给出的答案是基于我认为您的问题所在:让我知道是否有帮助。

Dimension inner join with fact table, get the values from dimensions and insert into fact... 维度内部与事实表联接,从维度获取值并将其插入事实...

or else create the fact less fact way 否则创造事实少事实的方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM