Formal languages are basis for creation of DB query languages (Alpha, QUEL, QBE, SQL)
Property of binary relations:
Operation ϕ is commutative if А ϕ В = B ϕ A
Operation ϕ is associative if (А ϕ В) ϕ С = А ϕ (В ϕ С)
Operation ϕ is distributive with respect with other operation θ, if
А ϕ (В θ С ) = (А ϕ В) θ (А ϕ С)
Set-theoretic operations require compatibility of their operands
The operation commutative, associative and distributive with respect to the intersection .
Example:
The operation not commutative and associative and distributive.
Т(А) = R(А) ⎯ S(А) = {t | t ∈ R & t ∉ S}
Example:
Note: Relational algebra do not use set-theoretic complement operation!!!
The operation commutative, associative and distributive with respect to union.
Т(А) = R(А) ∩ S(А) = {t | t ∈ R & t ∈ S}
Example:
Intersection is expressed via difference: R ∩ S = R – (R – S)
S(B) = R[B] = {t[B] ⏐ t ∈ R}
Projection is denoted as: R[B] или πВ(R)
Example:
Note: Duplicate tuples are deleted
Set of attributes М = (A1,…, Ak) and N = (B1,…,Bn) are
θ-comparable, if k = n and (Ai, Bi) are θ‑comparable. In this case expression M θ N means the following:
M θ N = (A1 θ B1) & … & (Ak θ Вk)
If t is a relation tuple, that contains sets of θ‑comparable attributes M and N, then the notation t[M] θ t[N] means the following:
(t[A1] θ t[B1]) & … & (t[Ak] θ t[Вk]).
Т(А) = R[M θ N] = {t | t ∈ R & t[M] θ t[N]}
Example:
The operation also has the following notation: σM θ N(R)
One of the attributes set M or N may be constant.
The operation is commutative and associative and distributive with respect of union and intersection.
Т(А,В) = R(А) x S(B) = {(t1,t2) | t1 ∈ R & t2 ∈ S}
Example:
T = R[М θ N]S = {(t1, t2) ⏐ t1 ∈ R ∧ t2 ∈ S ∧ t1[М] θ t2[N]}
Example:
The operation commutative and associative
The operation is also denoted as: R M θ NS
Join is expressed via the product and the selection:
R M θ NS = σM θ N(R x S)
Example:
R S R[B,C=B,C]S R*S
R[М θ N)S = {(t1) ⏐ t1 ∈ R ∧ t2 ∈ S ∧ t1[М] θ t2[N]}
Example:
R S R[B,C=B,C)S
R[М θ N)S = (R[М θ N]S)[A] – where А is a set of attributes of the relation R
Semijoin is expressed via the join and projection in such a way:
It1 ∈ R[M](R) = {(t2) ⏐ t2 ∈ R[N] ∧ (t1,t2) ∈ R}
Examples:
R Ia1∈ R[A](R) Ia2∈ R[A](R) I(a1,b1)∈ R[A,B](R) Ic2∈ R[C](R)
T(M) = R[N÷K]S = {t ⏐t ∈ R[M] & It(R) ⊇ S[K]}
The operation allows to formulate queries like this:
- Output teachers that teach lectures of ALL types.
Division operation is expressed by other operations of RA:
R[N÷K]S = R[M] – ((R(M) x S[K]) – R)[M]
Division operation is not commutative and associative
Example of DB for RA queries
Outputs names of professors from CSF faculty and subjects that they teach.
((((((FAC[FNo=Fno]DEP)
[DNo=DNo]TCH)
[TNo=TNo]LEC)
[SNo=SNo]SBJ)
[FAC.Name=‘CSF’])
[Post=‘prof’])
[TCH.Name, SBJ.Name]
LEC(GNo,TNo,...)
GRP(GNo, Course...)
TCH(TNo, Name...)
Example: Output names of faculties and their departments. Rezulted relation should have name FAC_DEP with attributes FName и DName respectively:
ρFAC_DEP(FName,DName)(FAC[FNo=FNo]DEP)[FAC.Name,DEP.Name]
2) Left outer join
FAC 〈Fno=Fno] DEP
FAC DEP
FNo Name Dean DNo Name Head FNo
F-1 CSF Ann D-1 SE Kate F-1
F-1 CSF Ann D-2 DBMS Lucy F-1
F-2 CTF Dick D-3 CAD Dave F-2
F-3 CEF Bob null null null null
F-4 CYB John null null null null
FAC
DEP
3) Right outer join
FAC [Fno=Fno〉 DEP
FAC DEP
FNo Name Dean DNo Name Head FNo
F-1 CSF Ann D-1 SE Kate F-1
F-1 CSF Ann D-2 DBMS Lucy F-1
F-2 CTF Dick D-3 CAD Dave F-2
null null null D-4 PL Stiv null
null null null D-5 CAM Sam null
FAC
DEP
FAC
DEP
Inner join
Left outer join
Right outer join
Full outer join
× × ×
σD=9
σB=C & D=9 σB=C σB=C B=C
σD=9
πA
πA
πA
πA
πA(σB=C & D=9(R(A, B)x S(C,D)))
Если не удалось найти и скачать доклад-презентацию, Вы можете заказать его на нашем сайте. Мы постараемся найти нужный Вам материал и отправим по электронной почте. Не стесняйтесь обращаться к нам, если у вас возникли вопросы или пожелания:
Email: Нажмите что бы посмотреть