3 The Relational Model MIS 304 Winter 2006. 3 2 Class Objectives That the relational database model takes a logical view of data That the relational model’s.

Slides:



Advertisements
Similar presentations
Relational Database Operators
Advertisements

The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
The Relational Database Model – some relations you might want to avoid!!!
The Relational Database Model
ITS232 Introduction To Database Management Systems
The Relational Database Model
Chapter 2 The Relational Database Model
Relational Algebra Relational Calculus. Relational Algebra Operators Relational algebra defines the theoretical way of manipulating table contents using.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
The Relational Database Model
LIS 557 Database Design and Management William Voon Michael Cole Spring '04.
Chapter 3 The Relational Database Model
The Relational Database Model. 2 Objectives How relational database model takes a logical view of data Understand how the relational model’s basic components.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
The Relational Database Model
LECTURE 3 THE RELATIONAL DATABASE MODEL
The Relational Database Model
The Relational Database Model
Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.
Chapter 3 Section 3.4 Relational Database Operators
ITEC 3220M Using and Designing Database Systems Instructor: Prof. Z.Yang Course Website: 3220m.htm
The Relational Database Model
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.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail | Muhd Eizan Shafiq Abd Aziz Faculty of Computer & Mathematical Sciences, UiTM Kedah.
3 & 4 1 Chapters 3 and 4 Drawing ERDs October 16, 2006 Week 3.
Database Systems, 9th Edition 1.  In this chapter, students will learn: That the relational database model offers a logical view of data About the relational.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 3 The Relational Database Model.
Database Systems: Design, Implementation, and Management Ninth Edition Chapter 3 The Relational Database Model.
Chapter 3 The Relational Database Model. Logical View of Data Relational Database – Designer focuses on logical representation rather than physical –
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Department of Mathematics Computer and Information Science1 CS 351: Database Systems Christopher I. G. Lanclos Chapter 3: The Relational Database Model.
3 1 Database Systems The Relational Database Model.
3 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Relational Algebra Operators (continued) Difference –Yields all.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Chapter 3 The Relational Database Model. Database Systems, 10th Edition 2 * Relational model * View data logically rather than physically * Table * Structural.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 3 The Relational Database Model.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
The Relational Database Model
Tables and Their Characteristics
Database Systems: Design, Implementation, and Management Tenth Edition
Chapter 4 Relational Model Characteristics
CIS 207 The Relational Database Model
Lecture 2 The Relational Model
THE RELATIONAL DATABASE MODEL
Theory behind the relational engine
Theory behind the relational engine
The Relational Database Model
Chapter 3 The Relational Database Model
Chapter 3 The Relational Database Model.
The 1:M Relationship (continued)
part 1 with pages 1-32 and part 2 with pages 33-69
Relational Database Model
Database Systems: Design, Implementation, and Management Ninth Edition
DATABASE SYSTEM.
The Relational Database Model
Chapter # 3 The Relational Database Model.
DCT 2053 DATABASE CONCEPT Chapter 2.2 CONTINUE
Database Systems: Design, Implementation, and Management
Relational Database Operators
Presentation transcript:

3 The Relational Model MIS 304 Winter 2006

3 2 Class Objectives That the relational database model takes a logical view of data That the relational model’s basic components are entities, attributes, and relationships among entities How entities and their attributes are organized into tables About relational database operators, the data dictionary, and the system catalog How data redundancy is handled in the relational database model

3 3 A Logical View of Data Still trying to free ourselves form the physical implementation problems. Relational model –Enables us to view data logically rather than physically –Reminds us of simpler file concept of data storage Table –Has advantages of structural and data independence –Resembles a file from conceptual point of view –Easier to understand than its hierarchical and network database predecessors

3 4 Tables and Their Characteristics Table: two-dimensional structure composed of rows and columns Contains group of related entities  an entity set –Terms entity set and table are often used interchangeably

3 5 Tables and Their Characteristics ( continued ) Table also called a relation because the relational model’s creator, Codd, used the term relation as a synonym for table Think of a table as a persistent relation: –A relation whose contents can be permanently saved for future use.

3 6 Characteristics of a Relational Table Table 3.1

3 7 STUDENT Table Attribute Values

3 8 Keys Consists of one or more attributes that determine other attributes Primary key (PK) is an attribute (or a combination of attributes) that uniquely identifies any given entity (row) Key’s role is based on determination –If you know the value of attribute A, you can look up (determine) the value of attribute B –This extends to the notion of a mathematical “function” f(x).

3 9 Keys ( continued ) Composite key –Composed of more than one attribute Key attribute –Any attribute that is part of a key Superkey –Any key that uniquely identifies each entity Candidate key –A superkey without redundancies

3 10 Null Values No data entry Not permitted in primary key Should be avoided in other attributes Can represent –An unknown attribute value –A known, but missing, attribute value –A “not applicable” condition Can create problems in logic and using formulas

3 11 Controlled Redundancy Makes the relational database work Tables within the database share common attributes that enable us to link tables together Multiple occurrences of values in a table are not redundant when they are required to make the relationship work Redundancy is unnecessary duplication of data

3 12 An Example of a Simple Relational Database

3 13 The Relational Schema for the CH03_SaleCo Database

3 14 Keys ( continued ) Foreign key (FK) –An attribute whose values match primary key values in the related table Referential integrity –FK contains a value that refers to an existing valid tuple (row) in another relation Secondary key –Key used strictly for data retrieval purposes

3 15 Relational Database Keys

3 16 Types of Participation Mandatory –Table A’s participation is mandatory if you must enter at least one record in Table A before you can enter values in Table B Optional –Table A’s participation is optional if you are not required enter at least one record in Table A before you can enter values in Table B

3 17 Degree of Participation Is the minimum and maximum number of records (entity instances) a Table must have associated with a single record in the related Table. Usually expressed as a pair of numbers Min,Max example 1,10.

3 18 Integrity Rules

3 19 Integrity Table Level Integrity = Entity Integrity Relationship Level Integrity = Referential Integrity Field Level Integrity = Domain Integrity –Ensures that every field is sound. The values are valid, consistent, and accurate

3 20 An Illustration of Integrity Rules

3 21 Relational Algebra Codd’s contribution included the idea that you could describe an “Algebra”, a consistent mathematical description of a DBMS. This is huge because if it is ‘mathematically consistent’ then when you perform an operation you know that it must return the results you expect.

3 22 Relational Database Operators Relational algebra –Defines theoretical way of manipulating table contents using relational operators: SELECT PROJECT JOIN INTERSECT –Use of relational algebra operators on existing tables (relations) produces new relations UNION DIFFERENCE PRODUCT DIVIDE

3 23 Relational Algebra Operators ( continued ) Union: –Combines all rows from two tables, excluding duplicate rows –Tables must have the same attribute characteristics Intersect: –Yields only the rows that appear in both tables

3 24

3 25 Relational Algebra Operators ( continued ) Difference –Yields all rows in one table not found in the other table—that is, it subtracts one table from the other Divide –Divide one table by the attributes of another –Seldom used

3 26

3 27 Product l Yields all possible pairs of rows from two tables l Also known as the Cartesian product

3 28 Relational Algebra Operators ( continued ) Select –Yields values for all rows found in a table –Can be used to list either all row values or it can yield only those row values that match a specified criterion –Yields a horizontal subset of a table Project –Yields all values for selected attributes –Yields a vertical subset of a table

3 29 Select

3 30 Project

3 31 Relational Algebra Operators ( continued ) Join –Allows us to combine information from two or more tables –Real power behind the relational database, allowing the use of independent tables linked by common attributes

3 32 Two Tables That Will Be Used in Join Illustrations

3 33 Natural Join Links tables by selecting only rows with common values in their common attribute(s) Result of a three-stage process: 1.PRODUCT of the tables is created 2.SELECT is performed on Step 1 output to yield only the rows for which the AGENT_CODE values are equal Common column(s) are called join column(s) 3.PROJECT is performed on Step 2 results to yield a single copy of each attribute, thereby eliminating duplicate columns

3 34 Natural Join, Step 1: PRODUCT

3 35 Natural Join, Step 2: SELECT

3 36 Natural Join, Step 3: PROJECT

3 37 Natural Join ( continued ) Final outcome yields table that –Does not include unmatched pairs –Provides only copies of matches If no match is made between the table rows, –the new table does not include the unmatched row

3 38 Natural Join ( continued ) The column on which we made the JOIN— that is, AGENT_CODE—occurs only once in the new table If the same AGENT_CODE were to occur several times in the AGENT table, –a customer would be listed for each match

3 39 This is IT This is what makes the relational database work in practical terms. You can use values from different but related tables work together to get the results you need.

3 40 Other Forms of Join Equijoin –Links tables on the basis of an equality condition that compares specified columns of each table –Outcome does not eliminate duplicate columns –Condition or criterion to join tables must be explicitly defined –Takes its name from the equality comparison operator (=) used in the condition Theta join –If any other comparison operator is used

3 41 Outer Join Matched pairs are retained and any unmatched values in other table are left null In outer join for tables CUSTOMER and AGENT, two scenarios are possible: –Left outer join Yields all rows in CUSTOMER table, including those that do not have a matching value in the AGENT table –Right outer join Yields all rows in AGENT table, including those that do not have matching values in the CUSTOMER table

3 42 Left Outer Join

3 43 Right Outer Join

3 44 The Data Dictionary and System Catalog Data dictionary –Used to provide detailed accounting of all tables found within the user/designer- created database –Contains (at least) all the attribute names and characteristics for each table in the system –Contains metadata—data about data –Sometimes described as “the database designer’s database” because it records the design decisions about tables and their structures

3 45 A Sample Data Dictionary

3 46 The Data Dictionary and the System Catalog ( continued ) System catalog –Contains metadata –Detailed system data dictionary that describes all objects within the database –Terms “system catalog” and “data dictionary” are often used interchangeably –Can be queried just like any user/designer- created table

3 47 Relationships within the Relational Database 1:M relationship –Relational modeling ideal –Should be the norm in any relational database design M:N relationships –Must be avoided because they lead to data redundancies 1:1 relationship –Should be rare in any relational database design

3 48 The 1:1 Relationship Found in any database environment One entity can be related to only one other entity, and vice versa Often means that entity components were not defined properly Could indicate that two entities actually belong in the same table Sometimes 1:1 relationships are appropriate

3 49 The 1:1 Relationship Between PROFESSOR and DEPARTMENT

3 50 The Implemented 1:1 Relationship Between PROFESSOR and DEPARTMENT

3 51 The 1:M Relationship Between PAINTER and PAINTING

3 52 The Implemented 1:M Relationship Between PAINTER and PAINTING

3 53 The 1:M Relationship Between COURSE and CLASS

3 54 The Implemented 1:M Relationship Between COURSE and CLASS

3 55 The M:N Relationship Can be implemented by breaking it up to produce a set of 1:M relationships Can avoid problems inherent to M:N relationship by creating a composite entity called a bridge or linking entity

3 56 The ERD’s M:N Relationship Between STUDENT and CLASS

3 57 Sample Student Enrollment Data

3 58 The M:N Relationship Between STUDENT and CLASS

3 59 Linking Table Implementation of a composite entity Yields required M:N to 1:M conversion Composite entity table must contain at least the primary keys of original tables Linking table contains multiple occurrences of the foreign key values Additional attributes may be assigned as needed

3 60 Converting the M:N Relationship into Two 1:M Relationships

3 61 Changing the M:N Relationship to Two 1:M Relationships

3 62 The Expanded Entity Relationship Model

3 63 The Relational Schema for the Ch03_TinyCollege Database

3 64 Data Redundancy Revisited Data redundancy leads to data anomalies –Such anomalies can destroy database effectiveness Foreign keys –Control data redundancies by using common attributes shared by tables –Crucial to exercising data redundancy control Sometimes, data redundancy is necessary

3 65 A Small Invoicing System

3 66 The Relational Schema for the Invoicing System

3 67 Summary ( continued ) Primary key uniquely identifies attributes –Can link tables by using controlled redundancy Relational databases classified according to degree to which they support relational algebra functions Relationships between entities are represented by entity relationship models Data retrieval speed can be increased dramatically by using indexes