关系代数基本运算_关系代数的基本和附加运算

关系代数基本运算

Definition

定义

Every DBMS must define a query language to enable users to access the data which is stored in the database. Relational Algebra is a procedural query language. It is used to query the database tables in order to access data in several ways. In this algebra, the input is a relation and output is also a relation. Operators are used to performing queries. It can be either unary or binary operator.

每个DBMS必须定义一种查询语言,以使用户能够访问存储在数据库中的数据。 关系代数是一种过程查询语言。 它用于查询数据库表,以便以多种方式访问​​数据。 在这个代数中,输入是一个关系,输出也是一个关系。 运算符用于执行查询。 它可以是一元或二进制运算符。

Basic Operations

基本操作

  • SELECT (unary)

    SELECT(一元)

  • PROJECT (unary)

    项目(一元)

  • UNION (binary)

    UNION(二进制)

  • SET DIFFERENCE (binary)

    设置差异(二进制)

  • CARTESIAN PRODUCT (binary)

    笛卡尔积(二进制)

  • RENAME (unary)

    重命名(一元)

Other Operations

其他作业

  • SET INTERSECTION

    设置相交

  • NATURAL JOIN

    自然加入

  • DIVISION

  • ASSIGNMENT

    分配

1)选择运算(σ) (1) Select Operation (σ))

This is used to get rows (tuples) from the table (relation) which fulfill a given condition.

这用于从满足给定条件的表(关系)中获取行(元组)。

Syntax: σp(r)

语法: σp(r)

Where σ is used for the Select Predicate, r is the name of relation or table, and p is used as the propositional logic, where we give the conditions that must be fulfilled by the data. In this, unary and binary operators like =, etc., to mention the condition can be used.

其中σ用于Select谓词,r是关系或表的名称,而p用作命题逻辑,在此我们给出数据必须满足的条件。 在这种情况下,可以使用一元和二进制运算符(例如=等)来提及条件。

Example: Student table and get data for students with age more than 20.

示例: Student表并获取20岁以上学生的数据。

σage> 20 (Student)

年龄> 20(学生)

2)项目运营(∏) (2) Project Operation (∏))

Project operation is used to project or show only a desired set of attributes of a relation. In other words, if we wish to see only the names all of the students in the Student table, then the project operation can be used. It will only project the columns or attributes chosen and will delete duplicate data from the columns.

项目操作用于计划或仅显示关系的所需属性集。 换句话说,如果我们希望仅在“学生”表中看到所有学生的姓名,则可以使用项目操作。 它只会投影选定的列或属性,并且将从列中删除重复的数据。

Syntax: ∏A1, A2...(r)

语法: ∏A1,A2 ...(r)

Here A1, A2 etc. are attribute names (name of columns).

在此,A1,A2等是属性名称(列名)。

Example:

例:

∏Name, Age(Student)

∏姓名,年龄(学生)

3)联合行动(∪) (3) Union Operation (∪))

This is used to fetch data from two (relations)tables or temporary relations (the result of other operation).

这用于从两个(关系)表或临时关系(其他操作的结果)中获取数据。

For union operation to work, the condition is that the relations(tables) taken should have an equal number of attributes(columns) and equal attribute domain. Even the duplicate tuples are automatically removed from the result.

为了使联合操作起作用,条件是所采用的关系(表)应具有相等数量的属性(列)和相等的属性域。 即使重复的元组也会自动从结果中删除。

Syntax: P ∪ Q

语法: P∪Q

Where P and Q are relations.

其中PQ是关系。

Example: if we have two tables Regular class and Extra class, both have an attribute student to save the name of the student, then,

示例:如果我们有两个表常规班级和额外班级,它们都具有属性student来保存学生的姓名,那么,

∏Student(Regular class) ∪ ∏Student(Extra class)

∏学生(普通班)∪学生(普通班)

4)设置差异(-) (4) Set Difference (-))

This operation is used to find data which present in one relation but not present in the other relation. This operation can be applied to two relations, just like the Union operation.

此操作用于查找以一种关系存在但不以另一种关系存在的数据。 就像联合操作一样,此操作可以应用于两个关系。

Syntax: P - Q

语法: P-Q

Where P and Q are relations.

其中PQ是关系。

Example: if we want to find the name of students who take the regular class but miss the extra class, then, the below operation can be used as:

示例:如果我们想查找参加普通班但错过额外班级的学生的姓名,则可以将以下操作用作:

∏Student(Regularclass) - ∏Student(Extraclass)

∏学生(普通班)-∏学生(额外班)

5)笛卡尔积(X) (5) Cartesian Product (X))

This operation is used to combine data of two separate relations into single and fetch data from the combined result relation.

此操作用于将两个单独关系的数据合并为单个数据,并从合并结果关系中获取数据。

Syntax: A X B

语法: AXB

Example: to find the information for Regular Class and Extra Class which are conducted in the morning, then, the following operation can be used:

示例:要查找早晨进行的常规班和额外班的信息,则可以使用以下操作:

σtime = 'morning' (Regularclass X Extraclass)

σtime='早晨'(常规类X附加类)

6)重命名操作(ρ) (6) Rename Operation (ρ))

Rename operation is used to change the name or rename the output relation for any query operation which returns or gives the result like Select, Project etc. Or in simple words to rename a relation(table).

重命名操作用于为返回或给出诸如Select,Project等结果的任何查询操作更改名称或重命名输出关系。或者用简单的语言重命名关系(表)。

Syntax: ρ(Relationnew, Relationold)

语法: ρ(Relationnew,Relationold)

翻译自: https://www.includehelp.com/dbms/basic-and-additional-operations-of-relational-algebra.aspx

关系代数基本运算

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值