调侃数据库4.1:关系代数(简单不得了的教程)
2017-05-03 本文已影响1820人
Dongle聊测试
上次我们介绍的是关系模型的一些东西,而这次主要来讲关系代数
![](https://img.haomeiwen.com/i5741745/a45705799b57b0b6.png)
先上图,大家理解理解
![](http://upload-images.jianshu.io/upload_images/5741745-a9cb16a85e234f99.png)
![](http://upload-images.jianshu.io/upload_images/5741745-4006f30276138875.png)
以下都以此举例
![](http://upload-images.jianshu.io/upload_images/5741745-ab397da553b11e88.png)
![](http://upload-images.jianshu.io/upload_images/5741745-52e362561ddfdcd3.png)
![](http://upload-images.jianshu.io/upload_images/5741745-b1696dce59cb1c89.png)
1 五个基本操作
🔥Selection
- ρ predicate (R)
-
罗列R中满足条件(predicate)的数据---水平
🔥Projection
- πcol1, . . . , coln (R)
-
定义R的垂直子集的关系,提取指定属性的值并消除重复---垂直
🔥Cartesian product(笛卡尔积)
- RXS
-
R关系与S关系的串联关系
🔥Union
- RUS
-
与数学中的并关系相同
🔥Set difference
- R-S
-
在R中消除S
2 三个派生操作
🔥Join
1. Theta join (θ-join)
![](http://upload-images.jianshu.io/upload_images/5741745-c138bc44f7d695b3.png)
![](http://upload-images.jianshu.io/upload_images/5741745-0acbb1444032b487.png)
![](http://upload-images.jianshu.io/upload_images/5741745-e6b609d20f2ab59c.png)
2. Natural join
在Client与Viewing的clientNo相同情况下,罗列出clientNo,fNale,lName,propertyNo,comment
![](http://upload-images.jianshu.io/upload_images/5741745-d84cf4e424099acb.png)
![](http://upload-images.jianshu.io/upload_images/5741745-772877fefd0126b3.png)
3. Outer join
展示那些没有匹配的值
![](http://upload-images.jianshu.io/upload_images/5741745-21dd4f2c39a03d0c.png)
🌺左外连接
Left outer join is join in which tuples from R that do not have matching values in common columns of S are also included in result relation.
![](http://upload-images.jianshu.io/upload_images/5741745-5fafbf9f64fed371.png)
将每个元组保持在结果的左关系中
![](http://upload-images.jianshu.io/upload_images/5741745-27ec718a80669c0c.png)
上图,大家注意这个null值选项,左边有值的是PropertyForRent,右边为null,显式左边而不显式右边,这便是左外连接
🌺右外连接
同左外连接类似,显式右关系
🌺全外连接
显式所有关系
🌺Semijoin
![](http://upload-images.jianshu.io/upload_images/5741745-25aeae3aeaf6f8ef.png)
![](http://upload-images.jianshu.io/upload_images/5741745-f0decd8ae7432026.png)
🔥Intersection
- R∩S
-
留下相同项
🔥Division
- R÷S
-
除法的意思,大家看下前面解释,已经很清楚了
保留V内与W相同的项,然后显式这个项所对应的值
今天的东西很多,也是大家需要记住的东西,请各位慢慢消化消化O(∩_∩)O哈哈哈~,不懂的地方请在下面留言