关系代数运算

When working with the relational model, we have 2 groups of operations we can use.

使用关系模型时 ,我们可以使用2组操作。

The first is called relational algebra, and it’s a procedural language.

第一种称为关系代数 ,它是一种过程语言

This is what SQL is based upon, and as such it is very important to learn - as SQL is the de-facto standard for working with relational databases.

这是SQL的基础,因此学习非常重要-因为SQL是使用关系数据库的实际标准。

The second is called relational calculus and instead of being procedural, it’s a declarative language. It’s a fundamental difference in how we interact with databases, because you don’t tell the database software what to do, you just tell it what you want, and let it sort out the details of how to do it.

第二种称为关系演算 ,而不是程序性的,它是一种声明性语言 。 这是我们与数据库交互的方式的根本区别,因为您没有告诉数据库软件该怎么做 ,而只是告诉您想要什么 ,然后让它整理出如何做的细节。

This is a common distinction among programming languages. In modern frontend, we say interaction with the DOM in React is declarative. Using vanilla JavaScript to modify the DOM is procedural.

这是编程语言之间的常见区别。 在现代的前端中,我们说与React中的DOM交互是声明性的。 使用原始JavaScript修改DOM是过程性的。

Languages like Datalog, QBE and QUEL have relational calculus as its base. I’m not going to talk about this because I think it’s a much more niche way of doing things compared to the more practical approach followed by SQL, but you can look at it if you want.

诸如Datalog , QBE和QUEL之类的语言都以关系演算为基础。 我不打算讨论这个问题,因为与SQL所采用的更实际的方法相比,这是一种更利基的处理方式,但是您可以根据需要进行查看。

Given this introduction, let’s go on with relational algebra.

有了这个介绍,让我们继续关系代数

We have 2 types of operations:

我们有2种操作类型:

  • primary operations

    主要操作

  • join operations

    加盟行动

关系代数中的主要运算 (Primary operations in relational algebra)

Primary operations are:

主要操作是:

  • union to get data from two tables, generating a sum of the tuples, as long as the two tables have the same columns and attribute types (domain).

    只要两个表具有相同的列和属性类型(域),就可以通过并集从两个表中获取数据,并生成元组的和。

  • difference to get data contained in the first table but not in the second table, generating a difference of the tuples, as long as the two tables have the same columns and attribute types (domain).

    差异以获取包含在第一个表中但不包含在第二个表中的数据,从而产生元组的差异,只要两个表具有相同的列和属性类型(域)即可。

  • cartesian product to get data from two tables into and generate one single table that combines the data of them, based on an attribute value.

    笛卡尔乘积可将两个表中的数据获取并生成一个基于属性值将它们的数据组合在一起的单个表。

  • select to only extract some of the tuples (rows) contained in a table based on certain criteria.

    选择仅基于某些条件提取表中包含的一些元组(行)。

  • project to generate a new table containing only one or more attributes (columns) of an existing table

    项目以生成仅包含现有表的一个或多个属性(列)的新表

  • rename used to rename an attribute, used to prevent conflicts when multiple tables have the same name for different data

    重命名用于重命名属性,用于防止多个表对不同数据使用相同名称时发生冲突

关系代数中的联接运算 (Join operations in relational algebra)

Joins are probably the most powerful operations you can perform with relational algebra. They build on top of primary operations, and they allow you to correlate data contained in different relations (tables).

连接可能是关系代数可以执行的最强大的运算。 它们建立在主要操作之上,并且使您可以关联包含在不同关系(表)中的数据。

Note: I’ll soon talk about joins in practice in a DBMS, this is mostly theory.

注意:我将很快讨论DBMS在实践中的联接,这主要是理论上的。

We have 2 main join versions: natural join and theta join. All the other versions are extracted from those 2.

我们有2个主要的join版本: 自然联接theta联接 。 所有其他版本均摘自那些2。

自然加入 (Natural Join)

Natural join correlates two relations (tables), and creates a new table based on the same values of an attribute.

自然联接将两个关系(表)相关联,并基于属性的相同值创建一个新表。

We need two relations with the same attribute name (column), first. Then if values in the attributes in relation A are unmatched in the attributes in relation B, the row is not part of the result, it’s ignored.

首先,我们需要两个具有相同属性名称(列)的关系。 然后,如果关系A中的属性值与关系B中的属性不匹配,则该行不是结果的一部分,将忽略该行。

Example:

例:

Relation A

关系A

Employee ID Name
1 Mark
2 Tony
3 Rick
员工ID 名称
1个 标记
2 托尼
3 里克

Relation B

关系B

Manager Name Employee ID
Todd 1
Albert 2
经理姓名 员工ID
托德 1个
阿尔伯特 2

We can perform a natural join to get the boss name for each employee:

我们可以进行自然加入以获得每个员工的老板姓名:

Employee ID Name Manager Name
1 Mark Todd
2 Tony Albert
员工ID 名称 经理姓名
1个 标记 托德
2 托尼 阿尔伯特

Since the relations have the Employee ID attribute name in common, it is only present once in the result, not 2 times.

由于这些关系具有共同的Employee ID属性名称,因此在结果中仅出现一次,而不是2次。

The employee #3 present in relation A, Rick, is not included in this table, because there’s no corresponding entry in relation B.

由于在关系B中没有相应的条目,因此关系A中存在的#3雇员Rick不包括在此表中。

θ联接 (Theta-join)

A theta-join allows to perform a join based on any criteria to compare two columns in two different relations, not just equality like the natural join does.

Theta-join允许根据任何条件执行连接以比较两个不同关系中的两个列,而不仅仅是自然连接那样的相等性。

It performs a cartesian product of two tables, and filters the results based on the selection we want to make.

它执行两个表的笛卡尔积,并根据我们要选择的内容过滤结果。

等值联接 (Equi-join)

The equi-join is a theta join, where the selection is based on equality between attribute values in the two different tables.

等值联接是theta联接,其中选择基于两个不同表中属性值之间的相等性。

The difference with the natural join is that we can choose which attributes names (columns) we want to compare.

自然连接的区别在于我们可以选择要比较的属性名称(列)。

We’ll talk much more about joins later when SQL is introduced, so we can use them in practice.

稍后在引入SQL时,我们将详细讨论联接,因此我们可以在实践中使用它们。

翻译自: https://flaviocopes.com/relational-algebra/

关系代数运算

关系代数运算_关系代数相关推荐

  1. mysql将sql转为关系代数_关系数据库基础:关系代数运算知识笔记

    1.关系代数运算符 集合运算符:并(U).差(-).交(∩).笛卡尔积(×) 专门的关系运算符:选择(∂).投影(π).连接(∞).除(÷) 算术比较符:大于(>).大于等于(≥).小于(< ...

  2. mysql将sql转为关系代数_MySQL实现关系代数运算

    MySQL实现关系代数运算 MySQL实现关系代数运算 MySQL实现关系代数运算 [var1] 两表的所有元组 select * from department; select * from ins ...

  3. 计算机等级关系代数,计算机二级:关系代数运算

    计算机二级:关系代数运算 计算机二级:关系代数运算 作者: 日期: 公共基础专题探究一一关系代数运算 序高频考点 号 1自然连接一种特殊的等值连接它要求两个关系中进行比较的分量必须是 相同的属性组,并 ...

  4. 【数据库基础】 几种基本的关系代数运算方法

    关系代数是一种抽象的查询语言,用对关系的运算来表达查询,作为研究关系数据语言的数学工具.1 目录 基本的关系代数算法 传统的集合运算 并 ∪\cup∪ 交 ∩\cap∩ 差 −-− 笛卡尔积(广义) ...

  5. 数据库MySQL关系模型之关系代数

    关系代数的运算按运算符的不同可分为 传统的集合运算(并.差.交.笛卡尔积) 专门的关系运算(选择.投影.连接.除运算) 关系代数运算的约束 某些关系代数操作,如并.差.交等需满足 "并相容性 ...

  6. 地理空间数据库复习笔记:概论、关系模型与关系代数

    我的GIS/CS学习笔记:https://github.com/yunwei37/ZJU-CS-GIS-ClassNotes <一个浙江大学本科生的计算机.地理信息科学知识库 > Lect ...

  7. 关系代数运算详细解释

    关系代数运算 关系代数的运算是一种数学运算,你主要功能是通过这种数学运行来指导数据库在关系操作上的程序实现. 如图所示,下面是关系代数的操作,上面是对应的SQL语句.如果我们熟悉关系代数的操作那么就很 ...

  8. MapReduce的关系代数运算

    关系代数 概念 R(A1,A2,...,An)R(A_1,A_2,...,A_n)R(A1​,A2​,...,An​)表示关系的名称是RRR,其属性是A1,A2,...,AnA_1,A_2,...,A ...

  9. 关系数据库基础:关系代数运算知识笔记

    1.关系代数运算符 集合运算符:并(U).差(-).交(∩).笛卡尔积(×) 专门的关系运算符:选择(∂).投影(π).连接(∞).除(÷) 算术比较符:大于(>).大于等于(≥).小于(< ...

最新文章

  1. 2.5 亿!华为成立新公司!
  2. U3D sorting layer, sort order, order in layer, layer深入辨析
  3. 1037:计算2的幂
  4. Java如何以及为什么使用Unsafe?
  5. 划分vlan实验心得体会_思科:相同vlan,不同交换机之间的通信
  6. error HLP: Help compilation failed with code 1
  7. Python每日一练(9)-批量爬取B站小视频
  8. hortonworks/registry 的Registry,registry存在,但是却查不到
  9. jfinal项目tomcat下部署
  10. Bzoj3576 [Hnoi2014]江南乐
  11. Laravel 数据库配置
  12. Protel99SE教程(一)——原理图封装
  13. 试比较瀑布模型、快速原型模型、增量模型和螺旋模型的优缺点,说明每种模型的适用范围。
  14. 值得借鉴:耗时两个月的求职经历
  15. Rais.vim 配置问题
  16. mysql ping命令_Ping命令详解
  17. 地面分割:Fast Segmentation of 3D Point Clouds for Ground Vehicles
  18. 使用pm2来保证Spring Boot应用稳定运行
  19. 2022年全球市场工业缝纫机总体规模、主要生产商、主要地区、产品和应用细分研究报告
  20. 【web 前端面试笔试题自总结】

热门文章

  1. python开源库——h5py快速指南
  2. Pygame - Python游戏编程入门(3)
  3. 关于程序可移植性的问题
  4. CA认证简单介绍和工作流程
  5. HR:说说你最大的优缺点?
  6. Batch Normalization:Accelerating Deep Network Training by Reducing Internal Covariate Shift 论文笔记
  7. 9 个非常实用的网络调试命令
  8. 微信开发(六)微信分享接入
  9. IntelliJ IDEA 14注册码
  10. 最新版Vmware虚拟机的下载方法、详细安装说明