Presentation is loading. Please wait.

Presentation is loading. Please wait.

Installment 7 Tables With No Column Presented by rexmen 2001 資管所.林彥廷. 690530031.

Similar presentations


Presentation on theme: "Installment 7 Tables With No Column Presented by rexmen 2001 資管所.林彥廷. 690530031."— Presentation transcript:

1 Installment 7 Tables With No Column Presented by rexmen 2001 資管所.林彥廷.

2 Installment 7 流程大綱 Relational Algebra OperatorRelational Algebra Operator Empty set in RDBEmpty set in RDB Tables and PredicateTables and Predicate Tables with No columnTables with No column TABLE_DUM and TABLE_DEETABLE_DUM and TABLE_DEE Effect on Relational AlgebraEffect on Relational Algebra

3 Relational Algebra Operator Select (Restrict)Select (Restrict) ProjectProject Cartesian ProductCartesian Product UnionUnion DifferenceDifference JoinJoin IntersectionIntersection DivideDivide 原始運算子 非原始運算子

4 Select (Restrict) 從一個 Table 中取出符合條件的資料,也就是取得 Row 的資料,請注意這裡的 Select 是運算子並不是 指 SQL 語法中的 Select 。 從一個 Table 中取出符合條件的資料,也就是取得 Row 的資料,請注意這裡的 Select 是運算子並不是 指 SQL 語法中的 Select 。 C1C2C3C4 Select * From T1 Where

5 Project 從一個 Table 中取出所需要的欄位,也就是取得 Column 的資料。 從一個 Table 中取出所需要的欄位,也就是取得 Column 的資料。 C1C2C3C4 Select C1, C2 From T1

6 Cartesian Product( 卡氏積 ) 將兩個 Table 以普通算術中的乘法原理相乘 後組合成一個 Table 。 將兩個 Table 以普通算術中的乘法原理相乘 後組合成一個 Table 。 C11C12 A1A2 B1B2 C1C2C21C22X1X2 Y1Y2 C11C12C21C22A1A2X1X2 A1A2Y1Y2 B1B2X1X2 B1B2Y1Y2 C1C2X1X2 C1C2Y1Y2 ╳=> Select * From T1, T2

7 Union 從兩個 Table 中取出聯集的資料,重複的資料只 取出一筆。 從兩個 Table 中取出聯集的資料,重複的資料只 取出一筆。 C1C2 X1X2 Y1Y2C1C2X1X2 Z1Z2C1C2X1X2 Y1Y2 Z1Z2 => Select * From T1 Union Select * From T2

8 Difference 從一個 Table 中刪除另一個 Table 中有的資料 。 從一個 Table 中刪除另一個 Table 中有的資料 。 C1C2 X1X2 Y1Y2C1C2X1X2 Z1Z2 C1C2Y1Y2 => Select * From T1 Where not exists ( Select * From T2 Where T1.C1 = T2.C1 and T1.C2 = T2.C2 )

9 Set of Relational DB C1C2C3…Cn Column / Attribute Row / Tuple TABLE / RELATION

10 Empty Set 空集合 (empty set) 仍然是一個集合,所以 RDB 集合定理所 構成,自然也要能符合含有空集合的性質。 空集合 (empty set) 仍然是一個集合,所以 RDB 集合定理所 構成,自然也要能符合含有空集合的性質。 Empty set of rowsEmpty set of rows Empty set of columnEmpty set of columnC1C2C3…Cn

11 Tables and Predicate Predicate :Predicate : –a Truth-valued Function( 真值函數 ) –Return True or False –Ex. F( e, set )F( e, set ) F( 3, {1,3,5,6} ) Ans : TrueF( 3, {1,3,5,6} ) Ans : True True, if e contained by set False, otherwise Proposition( 命題 ) / Instantiation( 實例 )

12 Predicate of Tables 可以說 predicate 是 table 的所表示的意義 可以說 predicate 是 table 的所表示的意義 每一個 table 有一個確切的 predicate 每一個 table 有一個確切的 predicate Ex. Table EMP with heading {E#, SAL, D#}Ex. Table EMP with heading {E#, SAL, D#} –“ Employee E# earns salary SAL and works in department D#. ” –E.g. EMP(E1, 50K, D1) 如果存在此列 (E1, 50K, D1) ,則此 proposition 的結果 為 True ,反之為 False 。 如果存在此列 (E1, 50K, D1) ,則此 proposition 的結果 為 True ,反之為 False 。

13 TABLE EMP(E#, SAL, D#) “ Employee E# earns salary SAL and works in department D#. ”“ Employee E# earns salary SAL and works in department D#. ” E#SALD# E150KD1 E235KD2 E360KD3 E440KD2 E550KD2 E642KD3 EMP

14 Project Away D# From EMP Table ES is derived from table EMP(E#, SAL, D#) by “ Projecting away ” column D#Table ES is derived from table EMP(E#, SAL, D#) by “ Projecting away ” column D# –Get table ES with heading {E#, SAL} –Predicate : “ THERE EXISTS a department D# SUCH THAT employee E# earns salary SAL and works in department D#. ”“ THERE EXISTS a department D# SUCH THAT employee E# earns salary SAL and works in department D#. ”

15 TABLE ES(E#, SAL) “ THERE EXISTS a department D# SUCH THAT employee E# earns salary SAL and works in department D#. ”“ THERE EXISTS a department D# SUCH THAT employee E# earns salary SAL and works in department D#. ” E#SALD# E150KD1 E235KD2 E360KD3 E440KD2 E550KD2 E642KD3 E#SALE235K E440K E550K EMP ES Project away D2 From EMP

16 Project Away E# From ES Table S is derived from table ES(E#, SAL) by “ Projecting away ” column E#Table S is derived from table ES(E#, SAL) by “ Projecting away ” column E# –Get table S with heading {SAL} –Predicate : “ THERE EXISTS a department D# SUCH THAT THERE EXISTS an employee E# SUCH THAT employee E# earns salary SAL and works in department D# ”“ THERE EXISTS a department D# SUCH THAT THERE EXISTS an employee E# SUCH THAT employee E# earns salary SAL and works in department D# ”

17 TABLE S(SAL) “ THERE EXISTS a department D# SUCH THAT THERE EXISTS an employee E# SUCH THAT employee E# earns salary SAL and works in department D# ”“ THERE EXISTS a department D# SUCH THAT THERE EXISTS an employee E# SUCH THAT employee E# earns salary SAL and works in department D# ” E#SALD# E150KD1 E235KD2 E360KD3 E440KD2 E550KD2 E642KD3 E#SALE235K E440K E550K EMP ES Project away D2 From EMPSAL40K Project away E4 From ES S

18 Project Away SAL From S Table Z is derived from table S(SAL) by “ Projecting away ” column SALTable Z is derived from table S(SAL) by “ Projecting away ” column SAL –Get table Z with heading { } –Predicate : “ THERE EXISTS a department D# SUCH THAT THERE EXISTS an employee E# SUCH THAT THERE EXISTS a salary SAL SUCH THAT employee E# earns salary SAL and works in department D#. ”“ THERE EXISTS a department D# SUCH THAT THERE EXISTS an employee E# SUCH THAT THERE EXISTS a salary SAL SUCH THAT employee E# earns salary SAL and works in department D#. ”

19 Table Z “ THERE EXISTS a department D# SUCH THAT THERE EXISTS an employee E# SUCH THAT THERE EXISTS a salary SAL SUCH THAT employee E# earns salary SAL and works in department D#. ”“ THERE EXISTS a department D# SUCH THAT THERE EXISTS an employee E# SUCH THAT THERE EXISTS a salary SAL SUCH THAT employee E# earns salary SAL and works in department D#. ”E#SALD#E150KD1 E235KD2 E360KD3 E440KD2 E550KD2 E642KD3 E#SALE235K E440K E550K EMP ES Project away D2 From EMPSAL40K Project away E4 From ES S Project away 40k From S

20 Table with No Column ! 此種 Table 是否能存在任何的列? 此種 Table 是否能存在任何的列? 在此種 Table 中存在著一種為 0-tuple 的列 在此種 Table 中存在著一種為 0-tuple 的列 – 因為一個列也是一種欄位的集合 –0-tuple 是一種欄位為空集合的一個欄位集合 – 此種 Table 只有一種列,即為 0-tuple( 一般正規的關聯式 資料庫中的列是要消除重複性的,因為 0-tuple 與其他 0- tuple 表示相同的列,故此種 table 只能至多有一個列。 ) –Table With No Column is useful ? Of Course, YES ! Of Course, YES !

21 TABLE_DUM and TABLE_DEE Table with No Column 只會有兩種情形:Table with No Column 只會有兩種情形: – 只有一個列 (TABLE_DEE) → True/Yes – 沒有任何列 (TABLE_DUM) →False/No SQL 難以精確的處理 Yes/NO 問題 ,因為 SQL 並不支援 Table with No Column 。SQL 難以精確的處理 Yes/NO 問題 ,因為 SQL 並不支援 Table with No Column 。 –Ex. ” Does employee E1 work in department D1? ” 畫出 TABLE_DUM 與 TABLE_DEE 的圖形是 困難的。 畫出 TABLE_DUM 與 TABLE_DEE 的圖形是 困難的。

22 Effect on Relational Algebra Identity – 普通算術中數字 1 為一個 Identity a*1 = 1*a = a, for all numbers aa*1 = 1*a = a, for all numbers a – 在關聯式代數中 TABLE_DEE 為一個 Identity T TIMES DEE = DEE TIMES T = T for all tables TT TIMES DEE = DEE TIMES T = T for all tables T

23 Product (Cartesian product) DEE T TIMES DEE = DEE TIMES T = T for all tables TT TIMES DEE = DEE TIMES T = T for all tables T C1C2 X1X2 Y1Y2 Z1Z2 Product TABLE_DEE =C1C2X1X2 Y1Y2 Z1Z2

24 Product (Cartesian product) DUM T TIMES DUM = DUM TIMES T = a table with the same heading as T but with no rows at all.T TIMES DUM = DUM TIMES T = a table with the same heading as T but with no rows at all. C1C2 X1X2 Y1Y2 Z1Z2 Product TABLE_DUM =C1C2

25 Join DEE T JOIN DEE = DEE JOIN T = a table with the same heading as T but with no rows at all.T JOIN DEE = DEE JOIN T = a table with the same heading as T but with no rows at all. C1C2 X1X2 Y1Y2 Z1Z2 JOIN TABLE_DEE =C1C2

26 Join DUM T JOIN DUM = DUM JOIN T = a table with the same heading as T but with no rows at all.T JOIN DUM = DUM JOIN T = a table with the same heading as T but with no rows at all. C1C2 X1X2 Y1Y2 Z1Z2 JOIN TABLE_DEE =C1C2

27 THE END rexmen 2001


Download ppt "Installment 7 Tables With No Column Presented by rexmen 2001 資管所.林彥廷. 690530031."

Similar presentations


Ads by Google