chapter 3
play

Chapter 3 Relational algebra and calculus 1 - PowerPoint PPT Presentation


  1. ���������������������������������������������������� ������������������������������������������� Chapter 3 Relational algebra and calculus 1 ������������������������������������������������������

  2. ���������������������������������������������������� ������������������������������������������� ���������������������������������������� • Operations on databases: – queries: "read" data from the database – updates: change the content of the database • Both can be modeled as functions from databases to databases • Foundations can be studied with reference to query languages: – relational algebra, a "procedural" language – relational calculus, a "declarative" language – (briefly) Datalog, a more powerful language • Then, we will study SQL, a practical language (with declarative and procedural features) for queries and updates 2 ������������������������������������������������������

  3. ���������������������������������������������������� ������������������������������������������� ������������������ • A collection of operators that – are defined on relations – produce relations as results and therefore can be combined to form complex expressions • Operators – union, intersection, difference – renaming – selection – projection – join (natural join, cartesian product, theta join) 3 ������������������������������������������������������

  4. ���������������������������������������������������� ������������������������������������������� ������������������������������� • Relations are sets, so we can apply set operators • However, we want the results to be relations (that is, homogeneous sets of tuples) • Therefore: – it is meaningful to apply union, intersection, difference only to pairs of relations defined over the same attributes 4 ������������������������������������������������������

  5. ���������������������������������������������������� ������������������������������������������� ����� Graduates Number Surname Age 7274 Robinson 37 Graduates ∪ Managers 7432 O’Malley 39 9824 Darkes 38 Number Surname Age 7274 Robinson 37 7432 O’Malley 39 Managers 9824 Darkes 38 Number Surname Age 9297 O’Malley 56 9297 O’Malley 56 7432 O’Malley 39 9824 Darkes 38 5 ������������������������������������������������������

  6. ���������������������������������������������������� ������������������������������������������� ������������ Graduates Number Surname Age 7274 Robinson 37 7432 O’Malley 39 9824 Darkes 38 Graduates ∩ Managers Number Surname Age Managers 7432 O’Malley 39 9824 Darkes 38 Number Surname Age 9297 O’Malley 56 7432 O’Malley 39 9824 Darkes 38 6 ������������������������������������������������������

  7. ���������������������������������������������������� ������������������������������������������� ���������� Graduates Number Surname Age 7274 Robinson 37 7432 O’Malley 39 Graduates - Managers 9824 Darkes 38 Number Surname Age Managers 7274 Robinson 37 Number Surname Age 9297 O’Malley 56 7432 O’Malley 39 9824 Darkes 38 7 ������������������������������������������������������

  8. ���������������������������������������������������� ������������������������������������������� ��������������������������������� Father Child Mother Child Paternity Maternity Adam Cain Eve Cain Adam Abel Eve Seth Abraham Isaac Sarah Isaac Abraham Ishmael Hagar Ishmael Paternity ∪ Maternity ���� � • the problem: Father and Mother are different names, but both represent a "Parent" • the solution: rename attributes 8 ������������������������������������������������������

  9. ���������������������������������������������������� ������������������������������������������� �������� • unary operator • "changes attribute names" without changing values • removes the limitations associated with set operators • notation: – ρ Y � X. (r) • example: – ρ Parent � Father. (Paternity) • if there are two or more attributes involved then ordering is meaningful: – ρ Location,Pay � Branch,Salary. (Employees) 9 ������������������������������������������������������

  10. ���������������������������������������������������� ������������������������������������������� ����������������� ρ Parent � Father. (Paternity) Paternity Father Child Father Child Adam Cain Adam Cain Adam Abel Adam Abel Abraham Isaac Abraham Isaac Abraham Ishmael Abraham Ishmael 10 ������������������������������������������������������

  11. ���������������������������������������������������� ������������������������������������������� ������������������ Father Child Mother Child Paternity Maternity Adam Cain Eve Cain Adam Abel Eve Seth Abraham Isaac Sarah Isaac Abraham Ishmael Hagar Ishmael ρ Parent � Father. (Paternity) ∪ ρ Parent � Mother. (Maternity) Parent Child Adam Cain Adam Abel Abraham Isaac Abraham Ishmael Eve Cain Eve Seth Sarah Isaac Hagar Ishmael 11 ������������������������������������������������������

  12. ���������������������������������������������������� ������������������������������������������� ���������������������������������������� Employees Staff Surname Branch Salary Surname Factory Wages Patterson Rome 45 Patterson Rome 45 Trumble London 53 Trumble London 53 ρ Location,Pay � Branch,Salary (Employees) ∪ ρ Location,Pay � Factory, Wages (Staff) Surname Location Pay Patterson Rome 45 Trumble London 53 Cooke Chicago 33 Bush Monza 32 12 ������������������������������������������������������

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend