Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.

Slides:



Advertisements
Similar presentations
Relational Algebra and Relational Calculus
Advertisements

RELATIONAL DATABASES. Relational data Structure RELATION: Table with columns and rows ATTRIBUTE: Column of a relation DOMAIN: Set of allowable values.
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Relational Algebra - Basic Operations CS263 Lecture 11.
Lesson II The Relational Model © Pearson Education Limited 1995, 2005.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
1 Minggu 3, Pertemuan 5 Relational Algebra (Cont.) Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
1 Minggu 2, Pertemuan 3 The Relational Model Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
1 Pertemuan 04 MODEL RELASIONAL Matakuliah: >/ > Tahun: > Versi: >
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
Thomas Connolly and Carolyn Begg’s
1-1 Thomas Connolly and Carolyn Begg’s Database Systems: A Practical Approach to Design, Implementation, and Management Chapter 4 Part One: Relational.
Relational Algebra & Relational Calculus Dale-Marie Wilson, Ph.D.
Relational Database Management System A type of database in which records are stored in relational form is called relational database management system.
Database Architecture The Relational Database Model.
Databases Illuminated
RELATIONAL ALGEBRA Objectives
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
Relational Model Session 6 Course Name: Database System Year : 2012.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Module 3: The Relational Model.  Overview Terminology Relational Data Structure Mathematical Relations Database Relations Relational Keys Relational.
Chapter 3 The Relational Model. 2 Chapter 3 - Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
Bayu Adhi Tama, ST., MTI. Introduction Relational algebra and relational calculus are formal languages associated with the relational.
C HAPTER 4 Relational Algebra and Relational Calculus Transparencies © Pearson Education Limited 1995,
Advanced Database Systems
The Relational Model Pertemuan 03 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
Relational Database. Database Management System (DBMS)
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.
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
CSC271 Database Systems Lecture # 8. Summary: Previous Lecture  Relation algebra and operations  Selection (Restriction), projection  Union, set difference,
12/2/2015CPSC , CPSC , Lecture 41 Relational Model.
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
CSC271 Database Systems Lecture # 7. Summary: Previous Lecture  Relational keys  Integrity constraints  Views.
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
CSCI 6315 Applied Database Systems Review for Midterm Exam I Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2014.
Chapter 4 The Relational Model Pearson Education © 2009.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
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
Ritu CHaturvedi Some figures are adapted from T. COnnolly
COMP3017 Advanced Databases
Relational Algebra and Relational Calculus
The Relational Database Model
Data Base System Lecture 6: Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
DATABASE SYSTEM.
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Algebra
Design tools and techniques for a relational database system
Chapter 4 The Relational Model Pearson Education © 2009.
Relational Algebra and Relational Calculus
Presentation transcript:

Relational Model & Relational Algebra

2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical relations and relations in the relational model. u Properties of database relations. u How to identify candidate, primary, and foreign keys. u Meaning of entity integrity and referential integrity.

3 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database, not the physical structure. u Attribute is a named column of a relation. u Domain is the set of allowable values for one or more attributes.

4 Relational Model Terminology u Tuple is a row of a relation. u Degree is the number of attributes in a relation. u Cardinality is the number of tuples in a relation. u Relational Database is a collection of normalized relations with distinct relation names.

5 Instances of Branch and Staff (part) Relations

6 Examples of Attribute Domains

7 Alternative Terminology for Relational Model

8 Database Relations u Relation schema –Named relation defined by a set of attribute and domain name pairs. u Relational database schema –Set of relation schemas, each with a distinct name.

9 Properties of Relations u Relation name is distinct from all other relation names in relational schema. u Each cell of relation contains exactly one atomic (single) value. u Each attribute has a distinct name. u Values of an attribute are all from the same domain.

10 Properties of Relations u Each tuple is distinct; there are no duplicate tuples. u Order of attributes has no significance. u Order of tuples has no significance, theoretically.

11 Relational Keys u Superkey –An attribute, or a set of attributes, that uniquely identifies a tuple within a relation. u Candidate Key –Superkey (K) such that no proper subset is a superkey within the relation. –In each tuple of R, values of K uniquely identify that tuple (uniqueness). –No proper subset of K has the uniqueness property (irreducibility).

12 Relational Keys u Primary Key –Candidate key selected to identify tuples uniquely within relation. u Alternate Keys –Candidate keys that are not selected to be primary key. u Foreign Key –Attribute, or set of attributes, within one relation that matches candidate key of some (possibly same) relation.

13 Relational Integrity u Null –Represents value for an attribute that is currently unknown or not applicable for tuple. –Deals with incomplete or exceptional data. –Represents the absence of a value and is not the same as zero or spaces, which are values.

14 Relational Integrity u Entity Integrity –In a base relation, no attribute of a primary key can be null. u Referential Integrity –If foreign key exists in a relation, either foreign key value must match a candidate key value of some tuple in its home relation or foreign key value must be wholly null. u Enterprise Constraints –Additional rules specified by users or database administrators.

15 Relational Algebra u Meaning of the term relational completeness. u How to form queries in relational algebra.

16 Introduction u Relational algebra is a formal language associated with the relational model. u Informally, relational algebra is a (high-level) procedural language

17 Relational Algebra u Five basic operations in relational algebra: Selection, Projection, Cartesian product, Union, and Set Difference. u These perform most of the data retrieval operations needed. u Also have Join, Intersection which can be expressed in terms of 5 basic operations.

18 Relational Algebra Operations

19 Relational Algebra Operations

20 Selection (or Restriction) u  predicate (R) –Works on a single relation R and defines a relation that contains only those tuples (rows) of R that satisfy the specified condition (predicate).

21 Example - Selection (or Restriction) u List all staff with a salary greater than £10,000.  salary > (Staff)

22 Projection u  col1,..., coln (R) –Works on a single relation R and defines a relation that contains a vertical subset of R, extracting the values of specified attributes and eliminating duplicates.

23 Example - Projection u Produce a list of salaries for all staff, showing only staffNo, fName, lName, and salary details.  staffNo, fName, lName, salary (Staff)

24 Union u R  S –Union of two relations R and S defines a relation that contains all the tuples of R, or S, or both R and S, duplicate tuples being eliminated. –R and S must be union-compatible. u 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.

25 Example - Union u List all cities where there is either a branch office or a property for rent.  city (Branch)   city (PropertyForRent)

26 Set Difference u R – S –Defines a relation consisting of the tuples that are in relation R, but not in S. –R and S must be union-compatible.

27 Example - Set Difference u List all cities where there is a branch office but no properties for rent.  city (Branch) –  city (PropertyForRent)

28 Intersection u R  S –Defines a relation consisting of the set of all tuples that are in both R and S. –R and S must be union-compatible.  Expressed using basic operations: R  S = R – (R – S)

29 Example - Intersection u List all cities where there is both a branch office and at least one property for rent.  city (Branch)   city (PropertyForRent)

30 Cartesian product u R X S –Defines a relation that is the concatenation of every tuple of relation R with every tuple of relation S.

31 Example - Cartesian product u List the names and comments of all clients who have viewed a property for rent. (  clientNo, fName, lName (Client)) X (  clientNo, propertyNo, comment (Viewing))

32 Example - Cartesian product and Selection u Use selection operation to extract those tuples where Client.clientNo = Viewing.clientNo.  Client.clientNo = Viewing.clientNo ((  clientNo, fName, lName (Client))  (  clientNo, propertyNo, comment (Viewing))) u Cartesian product and Selection can be reduced to a single operation called a Join.

33 Join Operations u Join is a derivative of Cartesian product. u Equivalent to performing a Selection, using join predicate as selection formula, over Cartesian product of the two operand relations. u One of the most difficult operations to implement efficiently in an RDBMS and one reason why RDBMSs have intrinsic performance problems.

34 Join Operations u Various forms of join operation –Theta join –Equijoin (a particular type of Theta join) –Natural join –Outer join –Semijoin

35 Example - Equijoin u List the names and comments of all clients who have viewed a property for rent. (  clientNo, fName, lName (Client)) Client.clientNo = Viewing.clientNo (  clientNo, propertyNo, comment (Viewing))

36 Natural join u R S –An Equijoin of the two relations R and S over all common attributes x. One occurrence of each common attribute is eliminated from the result.

37 Example - Natural join u List the names and comments of all clients who have viewed a property for rent. (  clientNo, fName, lName (Client)) (  clientNo, propertyNo, comment (Viewing))