Download presentation
Presentation is loading. Please wait.
1
Entity-Relationship Model Cont…..
CST203-2 Database Management Systems Lecture 5
2
There are 2 formal languages for relational model
Relational algebra Relational calculus
3
Relational Algebra
4
What is relational algebra?
The result? Sequence of relational algebra Divided into 2 groups
5
Special operations Set operations Selection Projection Join Rename
Union Intersection Set difference
6
Similar to normal algebra
Operation My HTML Symbol Projection PROJECT Selection SELECT Renaming RENAME Union UNION Intersection INTERSECTION
7
σ σ<Selection Condition> (R)
SELECT operation σ σ<Selection Condition> (R) σ – SELECT operator Selection Condition : Boolean expression R : relation If more selection conditions, Use ‘OR’, ‘AND’ and ‘NOT’
8
Select the students who has the GPA greater than 3.5
Horizontal partition Select the students who has the GPA greater than 3.5 σ σGPA > 3.5 (STUDENT) Student Table NID Name StudentId ExamId GPA
9
σsalary < 200(Employee) σsalary < 200 and nr >= 7(Employee)
id name salary 1 John 100 5 Sarah 300 7 Tom SQL Result Relational algebra select * from E where salary < 200 σsalary < 200(Employee) select * from E where salary < 200 and nr >= 7 σsalary < 200 and nr >= 7(Employee) id name salary 1 John 100 7 Tom id name salary 7 Tom 100
10
σ<Condition1>(σ<Condition2>(R)) = σ<Condition2>(σ<Condition1>(R)) σ<Cond1>(σ<Cond2>(σ<Cond3>(R))) = σ<Cond1> AND <Cond2> AND <Cond3>(R)
11
Assignment Name ENo DOB Address Sex Salary DNo Write the relational algebra for selecting all details whose department is 4 and whose salary is greater than 30,000 Write it in another way
12
PROJECT operation If want to choose a subset of the columns in a relation and discards the rest, Use Π Π Name, GPA (Student) Π <attribute list>(R)) Π<list1>(Π<list2>(R))) = Π<list>(R))
13
id name salary 1 John 100 5 Sarah 300 7 Tom SQL Result Relational algebra select salary from E PROJECTsalary(E) select nr, salary from E PROJECTnr, salary(E) salary 100 300 nr salary 1 100 5 300 7
14
Assignment Name ENo DOB Address Sex Salary DNo Write the relational algebra for selecting Name, Eno, and Address
15
Sequence of operations
STU_1stCLASS Πname(σGPA > 3.5 (STUDENT))
16
Assignment Name ENo DOB Address Sex Salary DNo Write the relational algebra for selecting Name, Eno, and Address of all male employees whose salary is greater than 20,000
17
CARTESIAN PRODUCT eid ename dept 1 Bill A 2 Sarah C 3 John dnr dname A
Marketing B Sales C Legal SQL Result Relational algebra select * from Employee, Department E X D enr ename dept dnr dname 1 Bill A Marketing B Sales C Legal 2 Sarah 3 John
18
INNER JOIN eid ename dept 1 Bill A 2 Sarah C 3 John dnr dname A
Marketing B Sales C Legal SQL Result Relational algebra select * from E, D where dept = dnr SELECTdept = dnr (E X D) or, using the equivalent join operation E JOINdept = dnr D eid name dept dnr dname 1 Bill A Marketing 2 Sarah C Legal 3 John
19
UNION operation Result Result1 υ Result 2
Result Πname(σGPA > 3.5 (STUDENT)) Result Πname(σ(GPA > 2.5 AND GPA < 3.5) (STUDENT)) Result Result1 υ Result 2
20
Result 1 Result 2 Result Name Amal Sunil Name Kamal Name Amal Sunil
22
INTERSECTION operation
Result Πname(σGPA > 3.5 (STUDENT)) Result Πname(σ(GPA > 2.5) (STUDENT)) Result Result Result 2 υ
23
Result 1 Result 2 Result Name Amal Sunil Name Amal Name Amal
25
SET DIFFERENCE Also called as MINUS Result Result1 – Result2
26
Name Amal Sunil Result 1 Result 2 Result Name Amal Name Sunil
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.