ssas对数据仓库_SSAS中的多对多关系简介

article/2025/9/19 23:58:39

ssas对数据仓库

In this article, I’m going to explain what many-to-many relationships in SSAS are and how to implement the same in a SQL Server Analysis Services (SSAS) project. For the sake of this article, we will only consider the Multidimensional Cube and not the Tabular. Also, this article assumes that you have some fair knowledge of building SSAS cubes from scratch.

在本文中,我将解释SSAS中的多对多关系以及如何在SQL Server Analysis Services(SSAS)项目中实现该关系。 为了本文的目的,我们将仅考虑多维多维数据集,而不考虑表格。 此外,本文假设您具有从头开始构建SSAS多维数据集的一些知识。

Often, in modeling dimensions and facts, BI developers face the issue of handling many-to-many relationships in the data model. In a SQL database or data warehouse, it is easier to implement the same; however, it gets complicated when the same model needs to be implemented in a multidimensional cube as well.

通常,在建模维度和事实时,BI开发人员会遇到在数据模型中处理多对多关系的问题。 在SQL数据库或数据仓库中,更容易实现。 但是,当同样需要在多维多维数据集中实现相同的模型时,它也会变得复杂。

了解多对多关系 (Understanding Many-to-Many Relationships)

Let us first understand what many-to-many relationships are all about. Consider a simple example of Students and Class. As you know, a student can register for one or more classes and a class can have one or more than one student. This is a simple example of many-to-many relationships. Other similar cases can be considered between Products and Customers. A customer can purchase one or more products, whereas a product can be purchased by one or multiple customers.

首先让我们了解一下多对多关系。 考虑一个简单的学生课堂的例子。 如您所知,一个学生可以注册一个或多个班级,一个班级可以拥有一个或多个学生。 这是多对多关系的简单示例。 在产品客户之间可以考虑其他类似情况。 一位客户可以购买一个或多个产品,而一个或多个客户可以购买一种产品。

However, we cannot define such kinds of many-to-many relationships directly in SQL. In order to implement such many-to-many relationships in a relational data model, we need to introduce an intermediate bridge table that has one-to-many relations with both the entities. Let us understand by following the figure below:

但是,我们不能直接在SQL中定义这种多对多关系。 为了在关系数据模型中实现这种多对多关系,我们需要引入一个中间桥表 ,该与两个实体都具有一对多关系。 通过下图让我们理解:

Many to Many Relationship Example

If you see in the figure above, the intermediate bridge table, in this case, is the “Enrollment” table, which has a many-to-one relation with both Students and the Class tables. Similarly, this approach can be considered for designing any other data models where many-to-many relationships need to be implemented.

如果你在上面,中间桥表图中看到的,在这种情况下,是“ 登记 ”表,其中有学生Class表一个多到一的关系。 类似地,可以考虑使用这种方法来设计需要实现多对多关系的任何其他数据模型。

在SSAS中实现多对多关系 (Implementing Many-to-Many Relationships in SSAS)

Now that we have some idea let us implement many-to-many relationships in SSAS. For demonstration purposes, I’m going to use the AdventureWorksDW2017 database as provided by Microsoft. This database is available for download free, and you can install the same on your local machine. In this data warehouse, there are also many-to-many relations, which states the reason for the purchase or sale of an item. For example, a sale can have one or more reasons linked to it and a sales reason can also be linked to multiple sales. In the warehouse, the Fact table is the “FactInternetSales” (marked in yellow) and the dimensions are “DimSalesReason” and “DimProduct” (marked in blue). Although there are many other dimensions and facts in the warehouse, it is out of scope for this article and won’t be covered here. The bridge table is created using the “FactInternetSalesReason” (highlighted in red).

现在我们有了一些想法,让我们在SSAS中实现多对多关系。 出于演示目的,我将使用Microsoft提供的AdventureWorksDW2017数据库。 该数据库可免费下载,您可以在本地计算机上安装该数据库。 在此数据仓库中,还存在多对多关系,该关系说明了购买或出售商品的原因。 例如,销售可以具有一个或多个与之相关的原因,而销售原因也可以与多个销售相关。 在仓库中,事实表为“ FactInternetSales ”( 以黄色标记 ),尺寸为“ DimSalesReason ”和“ DimProduct ”( 以蓝色标记 )。 尽管仓库中还有许多其他方面和事实,但这不在本文的讨论范围之内,因此不在此处讨论。 使用“ FactInternetSalesReason ”( 以红色突出显示 )创建桥表。

AdventureWorksDW Model for many to many relationships in ssas

Let us now go ahead and build many-to-many relationships in SSAS. You can follow the steps mentioned below and create the project.

现在让我们继续前进,在SSAS中建立多对多关系。 您可以按照下面提到的步骤创建项目。

Creating the SSAS Project

创建SSAS项目

Create a new Multidimensional project in SSAS.

在SSAS中创建一个新的多维项目

Connect it to the AdventureWorksDW2017 database and create the Data Source View accordingly.

将其连接到AdventureWorksDW2017数据库,并相应地创建数据源视图

In the Data Source View Wizard that appears, select the four tables as depicted in the figure below.

在出现的“ 数据源视图向导 ”中,选择四个表,如下图所示。

Data Source View Wizard

Click on Next and complete the wizard.

单击下一步 ,完成向导。

Completing the Data Source View Wizard

Once the Data Source View is ready, the next step is to create the Dimensions.

数据源视图准备就绪后,下一步就是创建Dimensions

创建尺寸 (Creating the dimensions)

Right-click on the Dimension and select New Dimension.

右键单击维度,然后选择新建维度

Adding New Dimension for many to many relationships in ssas

Select Use an Existing Table and click on Next.

选择“ 使用现有表” ,然后单击“ 下一步”

Using an Existing Table

Select DimProduct as table and Product Key as the Key Column and click on Next.

选择DimProduct作为表,选择Product Key作为键列 ,然后单击Next

Specify Source Dimension

Select English Product Name as the attribute and click on Next and finish the wizard.

选择English Product Name作为属性,然后单击Next并完成向导。

Selecting Dimension Attributes for DimProduct

Complete the similar steps for DimSalesReason and complete the wizard.

完成DimSalesReason的类似步骤并完成向导。

Selecting Dimension Attributes for DimSalesReason

创建立方体 (Creating the cube)

Now that the dimensions are ready, the next step is to create the cube.

现在已经准备好尺寸,下一步是创建多维数据集。

Right-click on Cube and select New Cube:

右键单击“ 多维数据集”,然后选择“ 新建多维数据集”

Add a New Cube

Select FactInternetSales and FactInternetSalesReason as measure groups and click Next.

选择FactInternetSalesFactInternetSalesReason作为度量值组,然后单击Next

Select Measure Groups

Select Sales Amount and Fact Internet Sales Reason Count as measure and click Next.

选择销售金额事实互联网销售原因计数作为度量,然后单击下一步

Select Measures

Once all the above steps are completed, click Finish to complete and close the wizard.

完成上述所有步骤后,单击“ 完成”以完成并关闭向导。

Complete the cube wizard

The cube is now created, and you can see the data model as follows.

现在创建了多维数据集,您可以看到如下数据模型。

Cube Data Model

Once the cube is created, deploy the cube onto the server. Right-click the cube and select Deploy.

创建多维数据集后,将多维数据集部署到服务器上。 右键单击多维数据集,然后选择Deploy

Deploy the cube

And finally, click Process to process the cube:

最后,单击“ 处理”以处理多维数据集:

Process the cube

Now that our cube has been processed, let browse the cube and see what the results are. Drag and drop the “Sales Reason Name”, “Sales Amount” and “Fact Internet Sales Reason Count” fields into the query designer. As you can see in the image below, the values for the Sales Amount are the same for all the reasons which are incorrect. The reason for this error is because the many-to-many relations between the fact tables are not yet defined.

现在我们的多维数据集已经处理完毕,让我们浏览多维数据集并查看结果。 将“ 销售原因名称 ”,“ 销售金额 ”和“ 事实Internet销售原因计数 ”字段拖放到查询设计器中。 如下图所示,由于所有不正确的原因,“销售额”的值均相同。 出现此错误的原因是,事实表之间的多对多关系尚未定义。

Browsing the cube

在SSAS中定义多对多关系 (Defining Many-to-Many Relationships in SSAS)

Let’s now define many-to-many relationships in SSAS. You can follow the steps below.

现在让我们在SSAS中定义多对多关系。 您可以按照以下步骤操作。

Add a new dimension for SalesOrderNumber. Since this is the column that we are going to use in the bridge column, we need to create a separate dimension for the same.

SalesOrderNumber添加一个新维度。 由于这是我们将在桥列中使用的列,因此我们需要为其创建单独的维度。

Adding the new dimension

Let the key column be as SalesOrderNumber. Complete the wizard by clicking Next and finally on Finish.

让键列为SalesOrderNumber 。 通过单击下一步 ,最后在完成结束向导。

Completing the wizard

Once the dimension is created, the next step is to add this new dimension to the cube.

一旦创建了维度,下一步就是将这个新维度添加到多维数据集。

Right-click on the Dimensions and select Add Cube Dimension.

右键单击维度,然后选择添加多维数据集维度

Add a Cube Dimension

Navigate to the Dimension Usage tab, and you’ll see the new dimension now available on the list. Select SalesOrderNumber adjacent to the FactInternetSales and click on the small box on the right. In the window that opens, select the Relationship Type as Fact.

导航到“ 维度用法”选项卡,您将在列表中看到新的维度。 选择SalesOrderNumber毗邻FactInternetSales度 ,然后点击右侧的小盒子。 在打开的窗口中,将“ 关系类型”选择为“ 事实”

Defining Fact Relation Type

Select the measure group FactInternetSalesReason for SalesReason. Click on the small box on the right hand and in the dialog that opens, select the Relation Type as Many-to-Many.

选择度量组FactInternetSalesReason作为SalesReason 。 单击右侧的小框,然后在打开的对话框中,将“ 关系类型”选择为“ 多对多”

Defining Many to Many relationships in ssas

浏览多维数据集 (Browsing the cube)

Now that we have implemented the necessary changes required for establishing many-to-many relationships in SSAS, we can now go ahead and start browsing the cube as we did in our previous step.

现在,我们已经实现了在SSAS中建立多对多关系所需的必要更改,现在我们可以像上一步一样继续浏览多维数据集了。

Browsing the cube

If you see the figure above, you can now see that the values for the Sales Amount are now being displayed correctly. Also, if you compare it with the previous example, you can see that some of the fields which did not have proper relations are also eliminated from the cube.

如果您看到上图,现在可以看到正确显示了“销售金额”的值。 此外,如果将其与前面的示例进行比较,您会发现从多维数据集中也删除了一些没有适当关系的字段。

结论 (Conclusion)

In this article, I have explained how we can implement many-to-many relationships in SSAS. Designing data models that include such many-to-many relations is quite complex and needs to be defined properly. If the relations are not defined properly, then it might lead to incorrect data and finally misleading information.

在本文中,我解释了如何在SSAS中实现多对多关系。 设计包含这种多对多关系的数据模型非常复杂,需要正确定义。 如果关系定义不正确,则可能导致数据错误,最终导致信息误导。

翻译自: https://www.sqlshack.com/introduction-to-many-to-many-relationships-in-ssas/

ssas对数据仓库


http://chatgpt.dhexx.cn/article/wasoK6jJ.shtml

相关文章

ssas连接mysql_BI之SSAS完整实战教程1 -- 开篇, BI简介 SSAS简介

文章提纲 商业智能(BI, Business Intelligence)基本概念 SSAS(SQL Server Analysis Services)相关工具(开发、管理和客户端) 总结 一、商业智能(BI, Business Intelligence)基本概念 商业智能的概念在1996年最早由加特纳集团(Gartner Group)提出&#xf…

ssas连接mysql_再谈通过http访问SSAS

问题: 在有些场景下,数据中心会分为不同的服务器场:数据库场和应用程序场。服务器场间有严格的防火墙控制,其中数据库场只能建立从应用程序场的防火墙穿越,也就是说不允许任何客户端直接连接到防火墙。 这种策略对于数…

ssas计算度量_如何在Analysis Services(SSAS)中创建中间度量

ssas计算度量 The whole premise of Analysis Services (SSAS) is to place business logic into a central repository (a database). This central repository should be easy to understand from the average reporting user. Simplicity for SSAS databases starts with th…

ssas表格模型 权限控制_性能调整SSAS表格模型

ssas表格模型 权限控制 Modeling for the xVelocity/Vertipaq engine is a completely different beast than modeling for your trusty multi-dimensional SSAS cubes. In-memory blazingly fast; At least that’s what you would think. As Tabular models gain popularity…

ssas从mysql获取数据库_SSAS-实用的DMV查询

以下查询,比较实用。 --All Cubes in database SELECT [CATALOG_NAME] AS [DATABASE],CUBE_CAPTION AS [CUBE/PERSPECTIVE],BASE_CUBE_NAME FROM $system.MDSchema_Cubes WHERE CUBE_SOURCE1 --All dimensions in Cube SELECT [CATALOG_NAME] as [DATABASE], CUBE_N…

ssas表格模型 权限控制_创建第一个SSAS表格模型数据库

ssas表格模型 权限控制 Considering BI environment, when comparing Multidimensional Vs Tabular model databases, both of them have their own advantages and purpose in data analytics and business intelligence. 考虑到BI环境,在比较多维VS表格模型数据库…

ssas 分层维度_通过SSAS维度层次结构增强数据分析

ssas 分层维度 介绍 (Introduction) This article will discuss how SSAS Dimension Hierarchies can be used to analyze data much efficiently. If you are a data analyst, you want to start the analysis with a higher hierarchy. Then navigate the narrow attributes …

ssas连接mysql_Web服务器(Websphere、Tomcat)使用olap4j连接多维数据库(Ssas)

最近项目需要使用Java连接到Sql Server多维数据库(Ssas)。在网上找到了一种通过可以通过IIS发布dll来作为jdbc连接串的方法,通过开源的olap4j的jar包,成功实现了类jdbc的方式连接到ssas。但实际应用中往往是通过web服务器的jdbc连接池的方式获得连接。 费…

ssas连接mysql_BI-SSAS简介篇

一、是什么? SSAS是用于SQLServer数据库用于BI的组件,通过SSAS可以创建多维数据库,并在之上进行数据挖掘操作。本文我们主要介绍一些关于SSAS数据分析的知识。接下来就让我们来一起了解一下吧。 商业智能提供的解决方案能够从多种数据源获取数…

ssas连接oracle性能,Analysis Services(SSAS) 性能优化

1、聚合选项中添加聚合,以空间换时间提升性能。 如下图: 性能提升百分比越高,聚合数越高,生成的Cube越大,这就是以空间换时间。 2、修改SSAS服务器上的线程池配置选项、提升并发数。 通过X:\Program Files\Microsoft S…

大数据时代:SSAS从入门到放弃

大数据时代到来,如何从数据中提取、挖掘对业务发展有价值的信息,为业务决策提供有力依据,推动精益化化的企业管理。商业分析师通常会使用各种数据分析工具,例如Excel、Tableau和PowerBI等对数据进行分析。OLAP就经常被用于对接这类…

ssas连接mysql_SSAS系列基础知识

1、什么是Cube? 简单 Cube 对象由基本信息、维度和度量值组组成。 基本信息包括多维数据集的名称、多维数据集的默认度量值、数据源和存储模式等。维度是多维数据集中使用的实际维度组。所有维度都必须先在数据库的维度集合中定义,然后才能在多维数据集中引用。度量…

SSAS多维数据分析创建

一、Visual Studio简介 Microsoft在 SQL Server Analysis Services (SSAS) 中,可以方便地创建复杂的联机分析处理(OLAP) 和数据挖掘解决方案。Analysis Services 工具提供了设计、创建和管理来自数据仓库的多维数据集和数据挖掘模型的功能,还提供对 OLAP…

SSAS介绍

文章提纲 商业智能(BI, Business Intelligence)基本概念 SSAS(SQL Server Analysis Services)相关工具(开发、管理和客户端) 总结 一、商业智能(BI, Business Intelli…

SSAS教程(一)——SSAS简介

SSAS全称SQL Server Analysis Services。Analysis Services 是在决策支持和商业分析中使用的分析数据引擎,它为商业报表和客户端应用程序提供了企业级语义数据模型,比如Power BI、 Excel、 Reporting Services 以及其他数据可视化工具。只要是支持Analys…

Java数组的初始化

Java数组初始化 1 一维数组初始化2 二维数组初始化 1 一维数组初始化 public class ArrayDemo1 {public static void main(String[] args) {// 格式一(动态初始化)int[] arr1 new int[3]; // 数组的长度(这里为3)必须指定// 格式二(静态初始化)int[] arr2 new int[]{1, 2, 3…

java类初始数组_java中数组初始化的三种方式是什么

java中数组初始化的三种方式是:1、静态初始化,如【int a[] {2, 0, 1, 9, 2020}】;2、动态初始化,如【int[] c new int[4]】;3、默认初始化,如【int[]dnew int[5]】。 初始化方式: 1、静态初始…

Java数组初始化、赋值与输出

文章目录 Java数组相关知识数组初始化一维数组二维数组 数组输出一维数组二维数组 Java数组相关知识 数组初始化 一维数组 初始化为0 int[] a; a new int[5]; int[] b new int[5]; 初始化为指定值 int[] a new int[]{0,1,2,3,4};//正确 int[] b {0,1,2,3,4};//正确&a…

java初始化array_java数组初始化方式

在使用一个新的数组之前,要先对其中的数值进行设置,也就是我们常说的初始化工作。因为数组有长度和内容的区分,所以常见的两种初始化方法是动态和静态,另外一种就是默认初始化。下面我们对数组的初始化概念进行理解,区…

c++ lamuda表达式mutable

1.lambda表达式 C11引入了Lambda表达式。Lambda表达式的引入,方便了简短函数的定义,为常用的一次性函数的定义和使用提供了很大的便利。 Lambda表达式实际上是一种匿名函数定义,常用来定义简单和不重复使用的函数。其可使用的外部变量、定义方…