关系演算_什么是关系演算?

关系演算

Contrary to Relational Algebra which is a procedural query language to fetch data and which also explains how it is done, Relational Calculus in non-procedural query language and has no description about how the query will work or the data will b fetched. It only focusses on what to do, and not on how to do it.

相反,关系代数这是一个程序性的查询语言来获取数据并且这也解释了它是如何完成的, 关系演算在非过程化查询语言,也没有关于查询如何工作或数据将b获取描述。 它只关注于做什么,而不是如何去做。

Relational Calculus exists in two forms:

关系演算以两种形式存在:

  1. Tuple Relational Calculus (TRC)

    元组关系演算(TRC)

  2. Domain Relational Calculus (DRC)

    领域关系演算(DRC)

元组关系演算(TRC) (Tuple Relational Calculus (TRC))

In tuple relational calculus, we work on filtering tuples based on the given condition.

在元组关系演算中,我们根据给定条件过滤元组。

Syntax: { T | Condition }

语法: { T | Condition } { T | Condition }

In this form of relational calculus, we define a tuple variable, specify the table(relation) name in which the tuple is to be searched for, along with a condition.

在这种形式的关系演算中,我们定义一个元组变量,指定要在其中搜索元组的表(关系)名称以及条件。

We can also specify column name using a . dot operator, with the tuple variable to only get a certain attribute(column) in result.

我们还可以使用来指定列名称. 点运算符,使用元组变量只能得到结果中的某个属性(列)。

A lot of informtion, right! Give it some time to sink in.

很多信息,对! 给它一些时间沉没。

A tuple variable is nothing but a name, can be anything, generally we use a single alphabet for this, so let's say T is a tuple variable.

元组变量不过是一个名称,可以是任何东西,通常我们为此使用单个字母,因此,可以说T是一个元组变量。

To specify the name of the relation(table) in which we want to look for data, we do the following:

要指定我们要在其中查找数据的关系(表)的名称,请执行以下操作:

Relation(T), where T is our tuple variable.

Relation(T) ,其中T是我们的元组变量。

For example if our table is Student, we would put it as Student(T)

例如,如果我们的表是Student ,则将其设置为Student(T)

Then comes the condition part, to specify a condition applicable for a particluar attribute(column), we can use the . dot variable with the tuple variable to specify it, like in table Student, if we want to get data for students with age greater than 17, then, we can write it as,

然后是条件部分,要指定适用于特定属性(列)的条件,我们可以使用. 点变量和元组变量来指定它,如表Student所示 ,如果我们要获取年龄大于17岁的学生的数据,则可以将其写为:

T.age > 17, where T is our tuple variable.

T.age > 17 ,其中T是我们的元组变量。

Putting it all together, if we want to use Tuple Relational Calculus to fetch names of students, from table Student, with age greater than 17, then, for T being our tuple variable,

综上所述,如果我们想使用元组关系演算从表Student中获取年龄大于17岁的学生的姓名,则对于T是我们的元组变量,

T.name | Student(T) AND T.age > 17

T.name | Student(T) AND T.age > 17

领域关系演算(DRC) (Domain Relational Calculus (DRC))

In domain relational calculus, filtering is done based on the domain of the attributes and not based on the tuple values.

在域关系演算中,过滤是基于属性的域而不是基于元组值进行的。

Syntax: { c1, c2, c3, ..., cn | F(c1, c2, c3, ... ,cn)}

语法: { c1, c2, c3, ..., cn | F(c1, c2, c3, ... ,cn)} { c1, c2, c3, ..., cn | F(c1, c2, c3, ... ,cn)}

where, c1, c2... etc represents domain of attributes(columns) and F defines the formula including the condition for fetching the data.

其中,c1,c2 ...等表示属性(列)的域, F定义包括获取数据的条件的公式。

For example,

例如,

{< name, age > | ∈ Student ∧ age > 17}

{< name, age > | ∈ Student ∧ age > 17}

Again, the above query will return the names and ages of the students in the table Student who are older than 17.

同样,以上查询将返回表Student中年龄大于17的学生的姓名和年龄。

翻译自: https://www.studytonight.com/dbms/relational-calculus.php

关系演算

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值