Ritu CHaturvedi Some figures are adapted from T. COnnolly

Slides:



Advertisements
Similar presentations
Relational Database Operators
Advertisements

Relational Algebra and Relational Calculus
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Database Systems Chapter 6 ITM Relational Algebra The basic set of operations for the relational model is the relational algebra. –enable the specification.
Relational Algebra - Basic Operations CS263 Lecture 11.
Relational Algebra Relational Calculus. Relational Algebra Operators Relational algebra defines the theoretical way of manipulating table contents using.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
1-1 Thomas Connolly and Carolyn Begg’s Database Systems: A Practical Approach to Design, Implementation, and Management Chapter 4 Part One: Relational.
Chapter 11.1 and 11.2 Data Manipulation: Relational Algebra and SQL Brian Cobarrubia Introduction to Database Management Systems October 4, 2007.
RELATIONAL ALGEBRA Objectives
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
Chapter 3 Section 3.4 Relational Database Operators
Relational Algebra - Chapter (7th ed )
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
Bayu Adhi Tama, ST., MTI. Introduction Relational algebra and relational calculus are formal languages associated with the relational.
Advanced Database Systems
Relational Algebra – Part 2
The Relational Algebra and Calculus
From Relational Algebra to SQL CS 157B Enrique Tang.
Chapter 6 The Relational Algebra Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2009.
Chapter 5 Relational Algebra Pearson Education © 2014.
1 Geog 357 – Introduction to GIS The Relational Language.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Part a The Relational Algebra and Relational Calculus Hours 1,2.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Al-Maarefa College for Science and Technology INFO 232: Database systems Chapter 3 “part 2” The Relational Algebra and Calculus Instructor Ms. Arwa Binsaleh.
Relational Algebra MBAD 613 R. Nakatsu. Relational Data Manipulation Language Query-by-Example; Query-by-Form Transform-Oriented Languages Relational.
Advanced Relational Algebra & SQL (Part1 )
CSC271 Database Systems Lecture # 8. Summary: Previous Lecture  Relation algebra and operations  Selection (Restriction), projection  Union, set difference,
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
CSC271 Database Systems Lecture # 7. Summary: Previous Lecture  Relational keys  Integrity constraints  Views.
Dr. Mohamed Hegazi1 The Relational Algebra and Relational Calculus.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
LECTURE THREE RELATIONAL ALGEBRA 11. Objectives  Meaning of the term relational completeness.  How to form queries in relational algebra. 22Relational.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 6 th Edition Chapter 8: Relational Algebra.
CSE202 Database Management Systems
Database Systems Chapter 6
Chapter (6) The Relational Algebra and Relational Calculus Objectives
Relational Algebra Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
COMP3017 Advanced Databases
Module 2: Intro to Relational Model
Chapter # 6 The Relational Algebra and Calculus
Fundamental of Database Systems
Relational Algebra - Part 1
The Relational Algebra and Relational Calculus
Relational Algebra and Relational Calculus
Chapter 2: Intro to Relational Model
Elmasri/Navathe, Fundamentals of Database Systems, 4th Edition
Chapter 4 The Relational Algebra and Calculus
The Relational Algebra and Calculus
LECTURE 3: Relational Algebra
The Relational Algebra and Relational Calculus
DATABASE SYSTEM.
Lecture 3 Relational Algebra and SQL
The Relational Algebra
Chapter 2: Intro to Relational Model
The Relational Algebra
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Chapter 4 Relational Algebra
Presentation transcript:

Ritu CHaturvedi Some figures are adapted from T. COnnolly Chapter on Relational Algebra Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly INTRODUCTION Relational algebra and relational calculus are formal languages associated with the relational model. Informally, relational algebra is a (high-level) procedural language and relational calculus a non-procedural language. However, formally both are equivalent to one another. A language that produces a relation that can be derived using relational calculus is relationally complete. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Properties of Relational Algebra Procedural language Operators operate on one or more relations and the result is always a relation without changing the original relations. This property is called closure. (If we perform one or more of the RA operations on a relational DB, we get back a result set that belongs to the same DB => relational DB is closed with respect to the operations of RA ). Both operands and results are relations, so output from one operation can become input to another operation. Allows expressions to be nested, just as in arithmetic. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Properties of Relational Algebra 5 basic operations in relational algebra: Selection, Projection, Cartesian product, Union, and Set Difference. (These perform most of the data retrieval operations needed). Also have Join, Intersection, and Division operations, which can be expressed in terms of 5 basic operations. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Unary Operators Select () (select in Class Notes ) Project (π) (project in Class Notes ) Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Binary Operators Set Operations Union Intersection Difference (minus) Cartesian Product (join) Join Operations Theta Join Equijoin Natural Join Outer Join Division Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Example : Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly UNARY OPERATORS Select () Selects a subset of tuples from a relation R that satisfy a certain predicate (or a Boolean condition). R1 = <Predicate>(R) Degree of R1 is the same as degree of R Cardinality of R1 <= Cardinality of R Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Examples Select employees who work in department number 4. Select employees who work in department number 4 and whose salary is greater than $70,000. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Project () Selects vertical subsets of a relation R extracting the values of specified attributes of R eliminating duplicates. R1 = <attribute-list>(R) Degree of R1  Degree of R Cardinality of R1  Cardinality of R (!!) Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Example: Retrieve the First Name, Last Name and Salary of all employees. Retrieve the First Name, Last Name and Salary of employees who work in department 4. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Example: Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Example: Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Set operations Two relations R(A1,….An) and S(B1,…Bn) are said to be Union Compatible if they have the same degree n and Dom(AI) = Dom(BI) where 1 I  n Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Union R  S: is a relation that includes all tuples that are either in R or in S or in both R and S, duplicate tuples being eliminated. If R and S have I and J tuples, respectively, union is obtained by concatenating them into one relation with a maximum of (I + J) tuples Example: List the names of all students and instructors. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Intersection R  S: is a relation that includes all tuples that are in both R and in S. Expressed using basic operations: R  S = R – (R – S) Example: List the names of those who are both students and instructors. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Difference R  S : is a relation that includes all tuples that are in R but not in S. Examples: List the names of students who are not instructors. List the names of instructors who are not students. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Example of set operators Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Cartesian Product R  S is a concatenation of every tuple of R with every tuple of S. If Degree(R ) = n and Degree(S) = m , then Degree(R  S) = n + m If Cardinality(R ) = t1 and Cardinality(S) = t2, then Cardinality(R  S) = t1 * t2 Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Example : R X S R1 R2 R1 X R2 Al A B No 1 2 3 Al No A 1 A 2 A 3 B 1 B 2 B 3 Ritu CHaturvedi Some figures are adapted from T. COnnolly

Example : Cartesian Product Ritu CHaturvedi Some figures are adapted from T. COnnolly

Example (Decomposing complex relations) List for all female employees, the names of their dependents. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Solution to Slide 23 Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly JOIN OPERATIONS Join is a derivative of Cartesian Product equivalent to performing a Selection operation using the join predicate as the selection, over the Cartesian product of the two operand relations. Join is the most difficult operation to implement in an RDBMS and is one of the reasons why relational systems have intrinsic performance problems. See the figure in Slide 8 Ritu CHaturvedi Some figures are adapted from T. COnnolly

Natural Join : The Process Links tables by selecting rows with common values in common attribute(s) Three-stage process Cartesian Product creates one table Select yields appropriate rows Project yields single copy of each attribute to eliminate duplicate columns Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Natural Join Information from two or more tables is combined Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Natural Join: R S The Natural Join is an Equijoin( next slide) of the two relations R and S over all common attributes x. One occurrence of each common attribute is eliminated from the result. Degree of a natural join = (Sum of degrees of R and S)  (number of attributes in x) Example: Retrieve the names of the managers of each department Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Other Joins EquiJOIN Links tables based on equality condition that compares specified columns of tables Does not eliminate duplicate columns Join criteria must be explicitly defined Theta JOIN EquiJOIN that compares specified columns of each table using operator other than equality one Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Other Joins Outer JOIN Matched pairs are retained Unmatched values in other tables left null Right and left Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Theta Join : R  S The Theta Join operation defines a relation that contains tuples satisfying the predicate  from the Cartesian Product of R and S R  S = (RS) Degree of Theta Join is the sum of degrees of R and S Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Example : Theta Join Retrieve the names of the managers of each department. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Equijoin When the predicate  contains only equality(=), theta join is called Equijoin. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Outer Join R S The (left) outer join is a join in which tuples from R that do not have matching values in the common attributes of S are also included in the result relation. Missing values in the second relation are set to null. ( Example : Retrieve all employee names and the department names they manage(if they manage a department) Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Left Outer Join Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly DIVISION OPERATOR R  S Let relation R be defined over attribute set A and relation S be defined over attribute set B such that B  A. Let C = A  B i.e. C is the set of attributes of R That are not attributes of S. The Division operation defines a relation over the attributes C that consists of the set of tuples from R that match the combination of every tuple in S. Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Example : Division - Retrieve the names of employees who work on all the projects that John Smith works on. Slide 8 Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly Example : Division Ritu CHaturvedi Some figures are adapted from T. COnnolly

Ritu CHaturvedi Some figures are adapted from T. COnnolly More examples Queries (RA) (Questions 1 to 7 : Solutions to be discussed in class) Ritu CHaturvedi Some figures are adapted from T. COnnolly