270 likes | 369 Views
Entity-Relationship Model Cont…. CST203-2 Database Management Systems Lecture 5. There are 2 formal languages for relational model Relational algebra Relational calculus. Relational Algebra. What is relational algebra? The result? Sequence of relational algebra Divided into 2 groups.
E N D
Entity-Relationship ModelCont….. CST203-2 Database Management Systems Lecture 5
There are 2 formal languages for relational model • Relational algebra • Relational calculus
What is relational algebra? • The result? • Sequence of relational algebra • Divided into 2 groups
Special operations • Selection • Projection • Join • Rename • Set operations • Union • Intersection • Set difference
SELECT operation σσ<Selection Condition>(R) • σ – SELECT operator • Selection Condition : Boolean expression • R : relation • If more selection conditions, • Use ‘OR’, ‘AND’ and ‘NOT’
Horizontal partition • Select the students who has the GPA greater than 3.5 σσGPA > 3.5 (STUDENT) Student Table
σ<Condition1>(σ<Condition2>(R)) = σ<Condition2>(σ<Condition1>(R)) σ<Cond1>(σ<Cond2>(σ<Cond3>(R))) = σ<Cond1> AND <Cond2> AND <Cond3>(R)
Assignment • 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
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))
Assignment • Write the relational algebra for selecting Name, Eno, and Address
Sequence of operations STU_1stCLASSΠname(σGPA > 3.5 (STUDENT))
Assignment • Write the relational algebra for selecting Name, Eno, and Address of all male employees whose salary is greater than 20,000
UNION operation Result 1 Πname(σGPA > 3.5 (STUDENT)) Result 2 Πname(σ(GPA > 2.5 AND GPA < 3.5) (STUDENT)) Result Result1 υ Result 2
Result 1 • Result 2 • Result
INTERSECTION operation Result 1 Πname(σGPA > 3.5 (STUDENT)) Result 2 Πname(σ(GPA > 2.5) (STUDENT)) Result Result1 Result 2 υ
Result 1 • Result 2 • Result
SET DIFFERENCE • Also called as MINUS Result Result1 – Result2
Result 1 • Result 2 • Result