23
Computer Science Centre University of Indonesia Inform ation M anagem ent R ESEA R C H G R O U P Relational Database & Relational Algebra Chapter 5, Elmasri & Navathe (2000)

Relational Database & Relational Algebra

  • Upload
    devlin

  • View
    125

  • Download
    0

Embed Size (px)

DESCRIPTION

Relational Database & Relational Algebra. Chapter 5, Elmasri & Navathe (2000). Tuples, Domains. Ordering. Usually the tuples must be ordered It may not be ordered if the attributes are explicit in the tuples. Relational Database Schema. Relational Database State. Naming of attributes. - PowerPoint PPT Presentation

Citation preview

Page 1: Relational Database &  Relational Algebra

Computer Science CentreUniversity of Indonesia

In fo rm ationM anagem entR E S E A R C H G R O U P

Relational Database & Relational Algebra

Chapter 5,Elmasri & Navathe (2000)

Page 2: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Tuples, Domains

Page 3: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Ordering

• Usually the tuples must be ordered• It may not be ordered if the attributes

are explicit in the tuples

Page 4: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Relational Database Schema

Page 5: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Relational Database State

Page 6: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Naming of attributes

• Same names, same thing• Same names, different things• Different names, same thing

Page 7: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Entity integrity constraints

• Primary key can not be null

Page 8: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Referential Integrity Constrains

• Maintain consistency between 2 tuples relations

• Example:– Every DNO (Dept Number) on each

EMPLOYEE must match one of the actual department number

• The DNUMBER attribute of DEPARTMENT is the foreign key

Page 9: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Foreign Key

• Can also refer to its own relation• Example: SSN of Supervisor• Also called state constraints• Transition constraints?

Page 10: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Referential

Page 11: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Database update constraints• Insert:

– No null on primary key, no same primary key, no foreign key

• Delete: – when it is referred by another tuple,

you can not delete it• Update

– No foreign key

Page 12: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Relational Algebra

• Select• Project• Rename• Union,

Intersection, Difference

• Join

• Equijoin• Natural Join• Cartesian

Product• Division• Aggregate• Outer Join

Page 13: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

SELECT & PROJECT

Page 14: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

RENAME

Page 15: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

UNION

Page 16: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

INTERSECT & DIFFERENCE

Page 17: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

CARTESIAN PRODUCT

Page 18: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

JOIN

• DEPT_MGR DEPARTMENT |X|MGRSSN=SSN

EMPLOYEE

• RESULT π DNAME, LNAME, FNAME (DEPT_MGR)

Page 19: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

NATURAL JOIN

• When the attribute of the tuples are the same

Page 20: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

DIVISIOIN

• SMITH LNAME=‘Smith’ (EMPLOYEE)

• SMITH_PNOS πPNOS(WORKS_ON |X| ESSN=SSN SMITH)

• SSN_PNOS πESSN, PNO(WORKS_ON)

• ??? SSN_PNOS SMITH_PNOS

Page 21: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

Page 22: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

AGGREGATE

Page 23: Relational Database &  Relational Algebra

In fo rm ationM anagem entR E S E A R C H G R O U P

LEFT OUTER JOIN

• TEMP EMPLOYEE ]X| SSN=MGRSSN DEPARTMENT

• RESULT π FNAM, MINIT, LNAME, DNAME (TEMP)