Title: Relational Databases
1???? ?????? ????????????? ??????
- Relational Databases
- And
- Relational Algebra
2??? ??? ????? ????
- ??? ????? ?????? ?????
- ??????, ????? ???? ????? ?????? ???? ???? ??????,
?? ?????? ????
???? ????? ????? ?????
year sname sid
3 white 240
3 jones 202
1 adams 450
?? ?? ????? ???? ????????
3???? ????? ??????
- ??????????? (???, ???????) ??????? ?? ????? ??
?????, ????? ???? - ??????? ??? ????? ??' ??????, ?? ?????? ????
- ??????? ?????? ?????? ??????? ?? ????
- ?????? ????? ????????
- ?????? ?????? ?????? ?? ????????
4???? ?????? (?????)
- ????? ??? ????? n-?? ?? ?????
- ????????? ??? n-??? ????? ?? ??? ????? ?? ?? ???
?????? ????, ?????? - (240,white,3) ? (white,240,3)
- ??? ?????? ?? ???? ??????? ???? ??????? ?????
???? ?? ???
year sname sid
3 white 240
year sid sname
3 240 white
5????
- ?? ????? ??? ??? ???? ??????? ??? ????? ??????
??? ?????, ????? ??? ??????? ??? ????
6????? ?? ??? (?? ?? ?????)
- ????? ??????????? (???? ???????) ?? ??? ?????
???? - ????? ?? ???? ????? ???
- sid, sname, year
- ???? ??? ?????, ?? ???? ??
??????? ???? ???? ???? ???
?????? ?? ???? ?? - ????? ?????? ?? ????? ?? ?????
year sname sid
3 white 240
3 jones 202
1 adams 450
7??? ??? ????? ????? ?? ??????
- ??????? ??? ??? ????? ????? ?? ??????
- ??? ??????? ???? ?? ???? ??????????
- ??????, ??? ??????? ???? ?? ???? ???? ??????
- ????? ??? ??? ?? ???? ?????, ?? ???? ????? ?????
?????? ???? ????? (??? ?????? ?????? ???? ???
???????? SQL) - ??????? ??????, ??? ??? ???? ?????
8??????
- ??? ??? ????? ????? ?? ??????
- ??? ??????? ???? ?? ???? ??????????
- ????? ??????????? ?? ???? ????? ????
- ????? ?????? ?? ????? ?? ????
- ?? ????? ??? ??? ???? ??????? ??? ??? ??????? ???
????
9?????? ??????
- ?????? ?????? ??? ???? ?? ?????? ?? ?????
- ?????? ?? ?? ????? ??? ???
- ????? ???? ???? ?????? ?? ?????? ?????? ?? ??????
?? ?????? ??????, ????? ???? ????? ???????
??????? - ?????? ?? ?????? ?????? ????? ???? ?????? ???????
?? ???? ?????? ?????
10???? ?????? ???? ???? ?? ??????
- ?????? ??????? ?? ??????, ???? ?????, ????? ?????
- ??? ?????? ??? ?????? ?? ?? ????? ??? ??? ????
????? ???? ?????? ????? ??? ?? ????? ????? ??
?????? - ?????? ???????? ???? ??? ?????
- ??? ????????
- ??? ????????
- ?????? ???????? ???? ?????? ?????? ?????
11????? ??????
course sid tid
os 202 20
calculus 450 10
db 202 20
db 240 20
year sname sid
3 white 240
3 jones 202
1 adams 450
dept tname tid
math cohen 10
cs levy 20
S Students T Teachers R Students, their
courses, and their teachers
12??????? ?? ?????? ??????
- ??????? ?????? ??????? ?????
- ????
- ?????
- ????? ??????
- ?????
- ????
- ???? ?? ?????? ?????? ?? "????? ??"
- ?????? ?????? ?????? ?????? ????? ??????? ????????
13???? Projection
- ????? ????? ??? ?????? (????? ?? ??? ???)
- ????? ????? ????? ??? ????????
- ?????? ????? ?????? ??????? ???? ?????? ??????
??????? - ?????? ???? ??? ????? ?? ??????, ?????? ???? ??
???? ??? ??? ?????, ?????? ???? ??????? ????
????? - ??????? ????? ????? ?"? ???????? ??
??????? ?? ????? ??????? ??????
14???? (????)
- ??? ???? ???? ?? ??? R ?? ??????? tid ?- course
?????? ?? ?????? - ??????
course sid tid
os 202 20
calculus 450 10
db 202 20
db 240 20
course tid
os 20
calculus 10
db 20
15Selection ?????
- ????? ?????? ??? ?????? (????? ?? ??? ???)
- ????? ?????? ????? ??? ?? ???????
- ?????? ?? ???? ??? (??? ?? ????) ???? ?????? ????
???? ?????? - ?? ????? ?????? ??? ???? ??????? ????? ??????
- ??????? ?????? ????? ?"? ???????? ??
??????? ?? ????? ???? ?????? ??????
16????? (????)
- ??? ????? ????? R ?? ?? ??????? ?? ????? ??-id
??? ??? 20, ?????? ?? ?????? - ??????
course sid tid
os 202 20
calculus 450 10
db 202 20
db 240 20
course sid tid
os 202 20
db 202 20
db 240 20
17????? ??????
- ?????? ??? ???? ?? ????? ??????? ????? ?????
??-id ??? ??? 20 - ??????
course sid tid
os 202 20
calculus 450 10
db 202 20
db 240 20
course
os
db
18????? ?? ????? ??????
- ????? ?????? ?? ????? ?????? ??? , ???? C
??? ????? - ????? ????? ???????? ???????? ?"? ?????? ??????
?? ?- (??? ???? ??????) - ?????? ??? ??????
- attribute1 op attribute2 ??
- attribute1 op constant
19?????? ???????
- ?????? ??????? (op) ??
- ????? ???? ???? ?"? ????? ???????
- ?? ????? ????? ??????? (char string), ??? ??????
???? ??? ??? ??????, ?????? -
-
20????
- ??????? ?????? ??? ?????? ????????? ?? ??????
?????, ???? substring, ??? ????? ?????? ?????? ??
?????? ???? ???? ???? ????? ????? ??????
-
21????? ?????? Cross Product
- ????? ?????? ??? ????? ???????, ??????? ?"? ,
???? ????? ?? ????? ?? ??? ??? ?? ?? ????? ??
???? ???? - ???? ??????? ?????? ???? ????? ????? ???????
?????? ???????? - ???? ??????? ?????? ???? ?????? ????? ???????
?????? ????????
22????? ?????? (????)
course sid tid
os 202 20
calculus 450 10
db 202 20
db 240 20
year sname sid
3 white 240
3 jones 202
1 adams 450
dept tname tid
math cohen 10
cs levy 20
S Students T Teachers R Students, their
courses, and their teachers
23dept tname )tid( course sid )tid(
math cohen 10 os 202 20
math cohen 10 calculus 450 10
math cohen 10 db 202 20
math cohen 10 db 240 20
cs levy 20 os 202 20
cs levy 20 calculus 450 10
cs levy 20 db 202 20
cs levy 20 db 240 20
24dept tname )tid( course sid )tid(
math cohen 10 os 202 20
math cohen 10 calculus 450 10
math cohen 10 db 202 20
math cohen 10 db 240 20
cs levy 20 os 202 20
cs levy 20 calculus 450 10
cs levy 20 db 202 20
cs levy 20 db 240 20
???? ?????? ??? ????? ?????? ?? ??????
????????. ?????? ????? ?????? ???????? ??????
????? ?????????? ???????, ?????? ????? ?? ????
??????????? ????. ??????, ??????? ?? ?????????
?????? ?????? ???????, ??? ????? ?????? ???
??????? ??? ??. ???????, ???? ??????? ??????
???????, ??? ????? ??, ???? ????? ?? ???? ??????
?? ??????? ?????? ??????? ??????? ???????? ?? ??
R ???????? ?? T.
25????? ?? Renaming
- ?????? ?????? ?"?
- ??????, ????? ?? ??????
- ????? ?? ???? ?? ?????? ???????
????? ?????? ?? ????? P(tid1,sid,course,tid2,tnam
e,dept) - ?? ????? ?? ?????? ??? P ????????? ??????? ????
???????????
26???????
- ???? ????? ?? ??? ???? ??????? ????? ???? ??? ?"?
?????? ???? - ?????? ????? (??????? ????) ???????? ??????
??????? ??? ???????? (????? 1 ??? ??????? ?????) - ?????? ?? ????? ??? ??? ?? ???? ?????? ???? (???,
??? ??? ?????? ?? ???? ??)
27dept tname course sid tid
math cohen os 202 20
math cohen calculus 450 10
math cohen db 202 20
math cohen db 240 20
cs levy os 202 20
cs levy calculus 450 10
cs levy db 202 20
cs levy db 240 20
28????? ?????
- ?????, ???? ???????? ??? ???? ???????? ???
- ?? ?????? ????? ??? ??? ???? ?????? ????
29dept tname course sid tid
math cohen calculus 450 10
cs levy os 202 20
cs levy db 202 20
cs levy db 240 20
30????
- ?? ?????? ?????? ??????? ?????? ??????, ?? ????
???? ?????? ?"? ?????? - ?????? ?????? 1 ?- 4
- ?????? ????? 1 ?????
- ???????, ?????? ???? ???? ?????? ?"? 1, 4
???' (??? ???? ???? ?????? ????? ??????), ??????
31?????Union
- ????? ??? ?????? ????? ???? ????, ????? ???
??????, ????? - ???? ?????? ???? ????? ?? ??????????, ??????
- ?????? ????? ???? ???????? ??? ????? ???? type
(???? ?? ??????? ?? ????? type ??? ????????) - ?? ?? ???????? ??????????? (?? ???? ??????????),
?? ?????? ??? - ???? ?????? ???? ???? ??????, ??????
- ?????? ????? ???? ????? ??? ????? ???? type
32?????
year sname sid
3 white 240
3 jones 202
1 adams 450
year sname sid
3 white 240
3 jones 202
1 katz 701
2 sapir 820
1 adams 450
year sname sid
1 katz 701
3 jones 202
2 sapir 820
33????Difference
- ????? ??? ?????? ???? ???? ???? ????? ???? ???
?????, ????? ??? ??????, ??? ?????? ????? ??
????? ??????
34?????
year sname sid
3 white 240
3 jones 202
1 adams 450
year sname sid
3 white 240
1 adams 450
year sname sid
1 katz 701
3 jones 202
2 sapir 820
35????? Intersection
- ????? ???? ???? ?????? ????? ?? ?????
- ??? ????? ????? ?????? ????? ?????? ????? ??????
?????
36?????
year sname sid
3 white 240
3 jones 202
1 adams 450
year sname sid
3 jones 202
year sname sid
1 katz 701
3 jones 202
2 sapir 820
37????? Join
- ????? ?????? ??? ????? ????? ?? ????? ??????
?????? (??????? ??????? ?? ????) - ????? ?????
- condition join ?? theta join (????? ?????)
- equi-join (??? ??????)
- natural join
38????? ????? Condition Join
- ????? ????? ??? ????? ?????? ????
- C ??? ????? ?????? ??????? ?????? ( , )
????????? ?????? - ????? ?? ?????? ??? ??? ???????? ????? A ?? R
???? ???????? ????? B ?? S - ???? ?? ??? ???? ?????????? ?? ???????, ???
- ??????
39???? ??????
- ??????
- ???? ????? ?????? (?????? ??????) ??? C, ????
??????? ?????? (???? ???? ?? ????????) ????? ???
C? - ?? ?- C ?????? ???????
- ?? ?- C ????? ?????? ???????
- i ??? ?????? ?? ?????? A ?- R
- kjn, ???? j ??? ?????? ?? ?????? B ?- S ?- n
??? ???? ??????? ?- R
40Equi-Join
- ????? ??????? ??? ????? ?????? ????
- ???? C ??? ????? (??????????) ?? ??????? ??????
- ?????, ?? ?????? ??? ?????? ??? ???????? ????? A
?? R ???? ???????? ????? B ?? S - ??????
41 ?????? ???? ?? Equi-Join
- ????? ?????? ??? ????? ?????? ????
- ???? C ??? ????? (??????????) ?? ??????? ??????
- R.A ????? ???????? A ?? R, ?- S.A ????? ????????
A ?? S (???? ??????????? ???? ???) - ??????
42???? ??????
- ??????
- ???? ??? C ???? C ??? ??? ????? ?????
- L ????? ?? ???? ??? (???, ????? ???) ??? ???
?????????? ???????? ?- C ?????, L ????? ?? ??
??????????? ?????? (???, ??? ??? ??????? ????? C
?? ??????)
43 ??? ????? ?????? (??? ????)
- ????? ?????? ???? ?? ????? ????? ????
- L ??? ????? ??????????? ???????? ????? C ?????,
?? ???????? A ????? ?????? L, ?? ????? C ??
?????? ???? ?? ???????
44 ????? ???? Natural Join
- ?? ?????? L ??????? ?? ??????????? ???????? ?- R
??- S, ?? ?????? ????? natural join, ??????? ????
??? ??? ?????? - ?????, ?????? ???? ?????? ?? ?? ????? ???????????
???????? ?- R ??- S ???????? ?? ???? ??? ??? ???
?????? ??????