Relational Database & Relational Algebra

Post on 13-Jan-2016

87 views 0 download

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

Transcript of 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)

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

Tuples, Domains

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

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

Relational Database Schema

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

Relational Database State

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

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

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

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?

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

Referential

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

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

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

SELECT & PROJECT

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

RENAME

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

UNION

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

INTERSECT & DIFFERENCE

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

CARTESIAN PRODUCT

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)

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

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

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

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

AGGREGATE

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)