核心!DB关系代数理论分析和用SQL语句实现

本文介绍了关系代数中六种常见的基本操作:选择、投影、并集、差集、笛卡尔积和重命名,并通过实例展示了如何使用SQL语句来实现这些操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

è¿éåå¾çæè¿°

两张表就相当于两个集合,当我们使用SELECT语句查询数据的时候,DBMS内部就是以集合相乘的运算得出结果

关系代数6种常见的基本操作:

select: σ

∧ and 、∨ or、┐not 

举个例子:

用 选择下表记录:

选择结果如下:

SQL语句实现方法:

select A,B,C,D from r where A=B and D>5;

 

project(投影):  ∏ 

注:Duplicate rows removed from result, since relations are sets集合

举个例子:

投影下表:

投影结果如下(要去除重复):

用SQL语句实现此功能:

select A,C from r;

 

union :  ∪

two tables must have the same arity 参数数量

The attribute domains must be compatible能共处的 [kəm'pætəbl]

 to find all courses taught in the Fall 2009 semester, or in the Spring 2010 semester, or in both

举个例子:

实现下表合并:

结果如下:

用SQL语句实现此功能:

(select A,B from r)union (select A,B from s);

 

set difference : -

举个例子:

操作下表:

结果如下:

(select A,B from r) except (select A,B from s);

 

Cartesian product:  x

Assume that attributes of two tables are disjoint不相交的

If attributes of r and s are not disjoint, then renaming must be used.

操作下表:

结果如下:

用SQL语句实现如下:

select * from r,s;

 

rename : p

 

 Additional operators:

Set intersection

Natural join

Assignment

Outer Join

 

Extended relational algebra operatiors:

Generalized Projection

Aggregate Functions 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值