Top Banner
데데데데데데 (Database) 데데 데데데 데데 데데 (Part 2) 데데데 데데데데데 IT 데데 데데데데데데데
33

데이터베이스 (Database) 관계 대수와 관계 해석 (Part 2) 문양세 강원대학교 IT 대학 컴퓨터과학전공

Jan 29, 2016

Download

Documents

lot

데이터베이스 (Database) 관계 대수와 관계 해석 (Part 2) 문양세 강원대학교 IT 대학 컴퓨터과학전공. 관계 대수 및 관계 해석 강의 요약. 관계 대수와 관계 해석. 단항 관계 연산 : 실렉트와 프로젝트 집합 이론과 관계 대수 연산 이항 관계 연산 : 조인과 디비전 연산 추가적인 관계 연산 관계 대수 질의의 예 투플 관계 해석 도메인 관계 해석. 관계 대수 질의의 예 (1/7). 관계 대수와 관계 해석. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Discrete Mathematics

(Database)

(Part 2)

IT Page 2 : : Database by Yang-Sae Moon2Page 3 (1/7) 1 : Research .

Database by Yang-Sae Moon3Page 4 (2/7) 2 : Stafford , , , .

Database by Yang-Sae Moon4Page 5 (3/7)

3 : 5 .

123123Database by Yang-Sae Moon5Page 6 (4/7)

4: Smith (worker) Smith (manager) .

Database by Yang-Sae Moon6Page 7 (5/7)

5: .( COUNT .)

Database by Yang-Sae Moon7Page 8 (6/7)

6: .

Database by Yang-Sae Moon8Page 9 (7/7)

7: (manager) .

Database by Yang-Sae Moon9Page 10 : : (tuple relational calculus) Database by Yang-Sae Moon10Page 11 (1/2) (Relational Calculus) SQL (tuple relational calculus) (domain relational calculus) (declarative) , (expressive power) Database by Yang-Sae Moon11Page 12 (2/2) (relationally completeness) L , L ( ) L (relationally complete) . (), (aggregate functions), (grouping), (ordering) .

Database by Yang-Sae Moon12Page 13 (1/2) (range) . : $50,000 . {t | EMPLOYEE(t) and t.SALARY > 50000} , EMPLOYEE(t) t EMPLOYEE . t t.SALARY > 50000 . t . Database by Yang-Sae Moon13Page 14 (2/2) t . {t.FNAME, t.LNAME | EMPLOYEE(t) and t.SALARY > 50000} SQL . ( ) SELECTT.FNAME, T.LNAMEFROMEMPLOYEE TWHERET.SALARY > 50000;

Database by Yang-Sae Moon14Page 15 (1/2) {t1.A1, t2.A2, ..., tn.An | COND(t1, t2, ..., tn, tn+1, tn+2, ..., tn+m)}t1, t2, ..., tn, tn+1, tn+2, ..., tn+m Ai ti COND (formula)(formula) (atom) Ri(ti) ti Ri (: EMPLOYEE(t))(ti.A op tj.B), op (=, 50000) (true) (false) , {t.FNAME, t.LNAME | EMPLOYEE(t) and t.SALARY > 50000}Database by Yang-Sae Moon15Page 16 (2/2)(formula): and, or, not .F1 F2 (F1 and F2), (F1 or F2), not(F1), not(F2) .

: EMPLOYEE(t) and t.SALARY > 50000 Database by Yang-Sae Moon16Page 17 (quantifiers) (universal quantifier) () (for all ) (existential quantifier) () (their exists )(free) (bound) ( ) t (t) (t) , t , . p. 186 ( ):F1: d.DNAME = ResearchF2: (t)(d.DNUMBER = t.DNO) d F1 F2 t F2

Database by Yang-Sae Moon17Page 18 F , (t)(F) .F t F , (t)(F) , .

F , (t)(F) .F t F (t)(F) , .

F t (t)(F) , . F (t)(F) , . Database by Yang-Sae Moon18Page 19 (1/4) 1: Research .Q1: {t.FNAME, t.LNAME, t.ADDRESS | EMPLOYEE(t) and (d) (DEPARTMENT(d) and d.DNAME = Research and d.DNUMBER = t.DNO)} ( | ) . ( | ) such that EMPLOYEE(t), DEPARTMENT(d) t d .d.DNAME = Research (selection condition)( SELECT )d.DNUMBER = t.DNO (join condition)( EQUI-JOIN ) Database by Yang-Sae Moon19Page 20 (2/4) 2: Stafford , , , , .Q2: {p.PNUMBER, p.DNUM, m.LNAME, m.BDATE, m.ADDRESS | PROJECT(p) and EMPLOYEE(m) and p.PLOCATION = Stafford' and ((d)(DEPARTMENT(d) and p.DNUM = d.DNUMBER and d.MGRSSN = m.SSN))}

8: , , .Q8: {e.FNAME, e.LNAME, s.FNAME, s.LNAME | EMPLOYEE(e) and EMPLOYEE(s) and e.SUPERSSN = s.SSN} Database by Yang-Sae Moon20Page 21 (3/4) 3: 5 .

Q3': {e.LNAME, e.FNAME | EMPLOYEE(e) and ((x) (w) (PROJECT(x) and WORKS_ON(w) and x.DNUM = 5 and w.ESSN = e.SSN and x.PNUMBER = w.PNO))}

Database by Yang-Sae Moon21Page 22 (4/4) 4: Smith . - Q4: {p.PNAME | PROJECT(p) and (((e)(w)(EMPLOYEE(e) and WORKS_ON(w) and w.PNO = p.PNUMBER and e.LNAME = Smith and e.SSN = w.ESSN)) or((m)(d)(EMPLOYEE(m) and DEPARTMENT(d) and p.DNUM = d.DNUMBER and d.MGRSSN = m.SSN and m.LNAME = Smith)))}AND/OR/NOT UNION or INTERSECTION and not Database by Yang-Sae Moon22Page 23 -- (x) (P(x)) (notx) (not(P(x)))(x) (P(x)) not(x) (not(P(x)))(x) (P(x) and Q(x)) (notx) (not(P(x)) or not(Q(x)))(x) (P(x) or Q(x)) (notx) (not(P(x)) and not(Q(x)))(x) (P(x) or Q(x)) not(x) (not(P(x)) and not(Q(x)))(x) (P(x) and Q(x)) not(x) (not(P(x)) or not(Q(x))) ( (implies) )(x) (P(x)) (x) (P(x)) (notx) (P(x)) not(x) (P(x)) Database by Yang-Sae Moon23Page 24 (1/3) -- , 3 3: 5 .Q3: {e.LNAME, e.FNAME | EMPLOYEE(e) and((x) (not (PROJECT(x)) or (not (x.DNUM = 5) or((w) (WORKS_ON(w) and w.ESSN = e.SSN and x.PNUMBER = w.PNO)))))}

Q3 Q3: {e.LNAME, e.FNAME | EMPLOYEE(e) and F}F = (x) (not(PROJECT(x)) or F1)F1 = (not(x.DNUM = 5) or F2)F2 = (w) (WORKS_ON(w) and w.ESSN = e.SSN and x.PNUMBER = w.PNO) Database by Yang-Sae Moon24Page 25 (2/3) -- Q3 1.Q3 e 5 . .2.F, not(PROJECT(x)) PROJECT x .3.F1, not(x.DNUM = 5) PROJECT , DNUM 5 x .4.F2 , 5 PROJECT .

Q3: {e.LNAME, e.FNAME | EMPLOYEE(e) and F}F = (x) (not(PROJECT(x)) or F1)F1 = (not(x.DNUM = 5) or F2)F2 = (w) (WORKS_ON(w) and w.ESSN = e.SSN and x.PNUMBER = w.PNO) Database by Yang-Sae Moon25Page 26 (3/3) -- 6: .Q6: {e.FNAME, e.LNAME | EMPLOYEE(e) and (not(d) (DEPENDENT(d) and e.SSN = d.ESSN))} Q6 Q6 Q6: {e.FNAME, e.LNAME | EMPLOYEE(e) and ((d) (not(DEPENDENT(d)) or not(e.SSN = d.ESSN)))}

7: .Q7: {e.FNAME, e.LNAME | EMPLOYEE(e) and ((d) (p) (DEPARTMENT(d) and DEPENDENT(p) and e.SSN = e.MGRSSN and p.ESSN = e.SSN))} Database by Yang-Sae Moon26Page 27 (Safe Expression) (finite) (infinite) , : {t | not(EMPLOYEE(t))} EMPLOYEE ,

Database by Yang-Sae Moon27Page 28 : : Database by Yang-Sae Moon28Page 29 (1/2) (domain variables) ? , n n Database by Yang-Sae Moon29Page 30 (2/2): 0: John B. Smith .Q0: {uv | (q) (r) (s) (EMPLOYEE(qrstuvwxyz) and q = John and r = B and s = Smith)}EMPLOYEE : qrstuvwxyzBDATE u, ADDRESS v q(FNAME), r(MINIT), s(LNAME) (q, r, s) (QBE ): Q0: {uv | EMPLOYEE(John, B,Smith,t,u,v,w,x,y,z)} Database by Yang-Sae Moon30Page 31 (1/2) 1: Research .Q1: {qsv | (z) (EMPLOYEE(qrstuvwxyz) and (l) (m) (DEPARTMENT(lmno) and l = Research and m = z))}(m = z) (l = Research)

2: Stafford , , , .Q2: {iksuv | (j) (PROJECT(hijk) and (t) (EMPLOYEE(qrstuvwxyz) and (m) (n) (DEPARTMENT(lmno) and k = m and n = t and j = Stafford)))} Database by Yang-Sae Moon31Page 32 (2/2) -- 6: .Q6: {qs | (t) (EMPLOYEE(qrstuvwxyz) and (not (l) (DEPENDENT(lmno) and t = l)))}

7: .Q7: {sq | (t) (EMPLOYEE(qrstuvwxyz) and ((j) (DEPARTMENT(hijk) and ((l) (DEPENDENT(lmno) and t = j and l = t)))))} Database by Yang-Sae Moon32Page 33 (SELECT), (PROJECT), (UNION), (SET DIFFERNECE), (Cartesion product) , , - ( ) Database by Yang-Sae Moon33