Relational Model Concepts. The relational model represents the database as a collection of relations. Each relation resembles a table of values. A table.

Slides:



Advertisements
Similar presentations
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
Advertisements

Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 (Continued) The Relational Algebra and Calculus.
CS4432: Database Systems II Query Operator & Algebraic Expressions 1.
Chapter 2 Relational Model (part II) Hankz Hankui Zhuo
Formal Relational Query Languages Chapter 6
Database Systems Chapter 6 ITM Relational Algebra The basic set of operations for the relational model is the relational algebra. –enable the specification.
Instructor: Mohamed Eltabakh
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
Chapter 11.1 and 11.2 Data Manipulation: Relational Algebra and SQL Brian Cobarrubia Introduction to Database Management Systems October 4, 2007.
The Relational Algebra and Calculus. Relational Algebra Overview Relational algebra is the basic set of operations for the relational model These operations.
Concepts of Database Management, Fifth Edition
Chapter 3 Section 3.4 Relational Database Operators
Relational Algebra Example Database Application (COMPANY) Relational Algebra –Unary Relational Operations –Relational Algebra Operations From Set Theory.
The Relational Model The relational model refers to a class of data models that have relations as the data structure, and incorporate some of all the query.
1 ICS 184: Introduction to Data Management Lecture Note 10 SQL as a Query Language (Cont.)
Chapter 6: Formal Relational Query Languages. 6.2 Chapter 6: Formal Relational Query Languages Relational Algebra Tuple Relational Calculus Domain Relational.
Relational Algebra - Chapter (7th ed )
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Relational Algebra Chapter 4 CIS 458 Sungchul Hong.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database.
Query Processing: Relational Algebra
Structured Query Language. Group Functions What are group functions ? Group Functions Group functions operate on sets of rows to give one result per group.
The Relational Algebra. 1 Relational Algebra Operations From Set Theory * UNIONUNION * INTERSECTIONINTERSECTION * MINUSMINUS * CARTESIAN OPERATIONCARTESIAN.
Oracle DML Dr. Bernard Chen Ph.D. University of Central Arkansas.
Bayu Adhi Tama, ST., MTI. Introduction Relational algebra and relational calculus are formal languages associated with the relational.
Advanced Database Systems
3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational.
The Relational Algebra and Calculus
Relational Algebra. 2 Outline  Relational Algebra Unary Relational Operations Relational Algebra Operations from Set Theory Binary Relational Operations.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Advanced Relational Algebra & SQL (Part1 )
Slide 6- 1 Additional Relational Operations Aggregate Functions and Grouping A type of request that cannot be expressed in the basic relational algebra.
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
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.
ASET Relational Algebra continues…. ASET Rename Operation Allows us to name, and therefore to refer to, the results of relational-algebra expressions.
IS 230Lecture 7Slide 1 Relational Algebra Lecture 8 Text Book – Chapter.
Database System Concepts, 6 th Ed. Chapter 6: Formal Relational Query Languages.
Relational Algebra National University of Computer and Emerging Sciences Lecture # 6 June 30,2012.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 6 th Edition Chapter 8: Relational Algebra.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Ritu CHaturvedi Some figures are adapted from T. COnnolly
Database Systems Chapter 6
Module 2: Intro to Relational Model
Chapter # 6 The Relational Algebra and Calculus
Fundamental of Database Systems
Relational Algebra - Part 1
Chapter 3: Relational Model III
Relational Algebra - Select & Project
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Elmasri/Navathe, Fundamentals of Database Systems, 4th Edition
Lecture 4 of 42 Relational Joins Wednesday, 30 January 2008
Instructor: Mohamed Eltabakh
Relational Algebra.
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Presentation transcript:

Relational Model Concepts

The relational model represents the database as a collection of relations. Each relation resembles a table of values. A table is called a relation. A row is called a tuple. A column header is called an attribute. The data type describing the type that can appear in each column is called a domain. A domain (D) is a set of atomic values.

Basic Structure Employee - Relation name Empno, ename, salary, dno – Attribute All records are Tuples

Query Language Categories –Procedural Example Relational Algebra –Non Procedural Example Relational Calculus

Relation Algebra It is procedural language It consists of set of operations that take one or more relations as input and produces new relation as output. The operation can be divided into three parts Basic operations Additional operations Extended operations

Basic operations Select (  ) Project (  ) Union (U) Rename (  ) Set difference (-) Cartesian product (x)

Additional operations Set intersection (  ) Natural join Division (  ) Assignment (  )

Extended operations Aggregate operations Outer join

Basic operations The Select operation (  ) –It is used to select a subset of the tuples (records) from a relation that satisfy a selection condition. Syntax  (R) Note : R is table name Example 1)  dno=10 (emp) 2)  ename=‘raja’ (emp) Note : Display eno,ename,salar dno (all heading)

Project operation The required attributes alone can be listed from a relation (selects certain columns from the table) Syntax  (R) Note : R is table name Example 1)  eno,salary (emp) display eno, salary (two column) 2)  ename  dno=10 (emp) Note : Display ename column only

The union operation (U) RUS is all tuples that are either in R or in S. Duplicate tuples are eliminated. Syntax RUS Example  ename (emp1) U  ename (emp2)

The Set difference operation ( - ) It is used to find tuples that are in one relation but are not in another. Syntax R - S Example  ename (emp) U  ename (empit)

Cartesian Product operation (X) It allows us to combine information from any 2 relations. Syntax R X S = { tq/t  R and q  s} Example  dno=10 (emp X dept)

Rename operation (  ) Allow us to name the relational algebra expressions Allow us to refer to a relation by more than one name. Example  temp (  eno,salary (emp))

Join operation R=(A,B,C,D) s=(E,B,D) –(A,B,C,D,E Column heading) R IXI S=(A,B,C,D,E) Example R IXI S =  r.A, r.B, r.C, r.D, s.E (  r.B =s.B and r.D=s.D (RXS)) equal  r.B =s.B and r.D=s.D (R IXI S))

Division operation ( r  s) R=(A1,A2,A3, …… Am, B1,B2,B3,…….Bn) S=(B1,B2,…..Bn) The result of r  s is r  s =(A1,A2,A3, …… Am)

Assignment Operation (  ) It can be assigned to a temporary relation variable (S). Example Temp (  )  eno,salary (emp) Temp1 (  )  eno,salary  salary>10000 (emp)

Aggregate functions Aggregate function takes a collection of values and returns a single values as a result. AVG – average value MIN – minimum value MAX – Maximum value SUM – Sum of values COUNT – number of record

Syntax G Aggregate_function (attribute_name) (relation name) Example G Sum(salary) (emp) dno G Sum(salary) (emp) Find sum of salary for employees to each department.

Difference between join (IXI) and Cartesian product (X) Join (IXI)Cartesian product (X) Only combinations of tuples satisfying the joint condition appear in the result. All combinations of tuples are included in the result.

employee (person_name, street, city) works (person_name, company_name, salary) Company (company_name,city) manages (person_name, manager_name) Consider the relation database, where the primary keys are underlined. Give an expression in relational algebra, SQL query of the following a)Find the names of all employees who work for First Bank Corporation b)Find the names and cities of residence of all employees who work for First Bank Corporation c)Find the names, street address, cities of residence of all employees who work for bank and earn more than Rs. 10,000 per annum. d)Find the names of all employees in this database who live in the same city as the company for which they work. e)Find the names of all employees who live in the same city and on the same street as do their managers. f)Find the names of all employees in this database who do not work for First Bank Corporation

employee (person_name, street, city) works (person_name, company_name, salary) Company (company_name,city) manages (person_name, manager_name) a) Find the names of all employees who work for First Bank Corporation Relation Algebra  person_name (  company_name="First Bank Corporation” (works)) SQL Query SQL> Select person_name from works where company_name=“First Bank Corporation”;

employee (person_name, street, city) works (person_name, company_name, salary) Company (company_name,city) manages (person_name, manager_name) b) Find the names and cities of residence of all employees who work for First Bank Corporation Relation Algebra  person_name, city (  company_name="First Bank Corporation” ^ employee.person_name=works.person_name (Employee X works)) SQL Query SQL> Select person_name, city from employee, works where company_name=“First Bank Corporation” and employee.person_name=works.person_name ;

employee (person_name, street, city) works (person_name, company_name, salary) Company (company_name,city) manages (person_name, manager_name) c) Find the names, street address, cities of residence of all employees who work for bank and earn more than Rs. 10,000 per annum. Relation Algebra  person_name,street,city (  company_name="First Bank Corporation” ^ Salary>10000 ^ employee.person_name=works.person_name (Employee X works)) SQL Query SQL> Select person_name, street, city from employee, works where company_name=“First Bank Corporation” and salary>10000 and employee.person_name=works.person_name ;

employee (person_name, street, city) works (person_name, company_name, salary) Company (company_name,city) manages (person_name, manager_name) d) Find the names of all employees in this database who live in the same city as the company for which they work. Relation Algebra  person_name (  employee.city=company.city ^ employee.person_name =works.person_name^company.company_name=works.company_name (Employee X works X company)) SQL Query SQL> Select person_namefrom employee, works, company where employee.city=company.city and works.comapany_name = company.company_name;

employee (person_name, street, city) works (person_name, company_name, salary) Company (company_name,city) manages (person_name, manager_name) e)Find the names of all employees who live in the same city and on the same street as do their managers. Relation Algebra  person_name (  employee.person_name=manges.person_name ^ company.city=employee.city (Employee X manages X company)) SQL Query SQL> Select person_name from employee,manages, company where employee.person_name=manages.person_name And company.city=employee.city;

employee (person_name, street, city) works (person_name, company_name, salary) Company (company_name,city) manages (person_name, manager_name) f) Find the names of all employees in this database who do not work for First Bank Corporation Relation Algebra  person_name (  employee.person_name<> First Bank Corporation” (Works)) SQL Query SQL> Select person_name from works where company_name<> “First Bank Corporation”;