43
Chapter 5 Chapter 5 The Relational The Relational Database Model: Database Model: Introduction Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis John Wiley & Sons, Inc.

Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

Embed Size (px)

Citation preview

Page 1: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

Chapter 5Chapter 5The Relational Database The Relational Database

Model: IntroductionModel: Introduction

Fundamentals of Database Management Systems, 2nd ed.

by

Mark L. Gillenson, Ph.D.

University of Memphis

John Wiley & Sons, Inc.

Page 2: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-22

Chapter ObjectivesChapter Objectives

Explain why the relational database model Explain why the relational database model became practical in about 1980. became practical in about 1980.

Define such basic relational database Define such basic relational database terms as relation and tuple. terms as relation and tuple.

Describe the major types of keys including Describe the major types of keys including primary, candidate, and foreign. primary, candidate, and foreign.

Page 3: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-33

Chapter ObjectivesChapter Objectives

Describe how one-to-one, one-to-many, and Describe how one-to-one, one-to-many, and many-to-many binary relationships are many-to-many binary relationships are implemented in a relational database. implemented in a relational database.

Describe how relational data retrieval is Describe how relational data retrieval is accomplished in concept with the select, project, accomplished in concept with the select, project, and join operators. and join operators.

Understand how the join operator facilitates data Understand how the join operator facilitates data integration in relational database. integration in relational database.

Page 4: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-44

Relational Database ModelRelational Database Model

In 1970, E. F. Codd published “A In 1970, E. F. Codd published “A Relational Model of Data for Large Shared Relational Model of Data for Large Shared Data Banks” in CACM.Data Banks” in CACM.

In the early 1980s, commercially viable In the early 1980s, commercially viable relational database management systems relational database management systems became available.became available.

Page 5: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-55

Relational Database ModelRelational Database Model

While relational database was very tempting in While relational database was very tempting in concept in the 1970s, it was not easily concept in the 1970s, it was not easily applicable in a real-world environment for applicable in a real-world environment for reasons related to performance.reasons related to performance.

The earlier hierarchical and network database The earlier hierarchical and network database management systems were just coming onto the management systems were just coming onto the commercial scene and were the focus of intense commercial scene and were the focus of intense marketing efforts by the software and hardware marketing efforts by the software and hardware vendors.vendors.

Page 6: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-66

The Relational Database The Relational Database ConceptConcept

Data Data appearsappears to be stored in what we have been to be stored in what we have been referring to as simple, linear files.referring to as simple, linear files.

Relational databases are based on Relational databases are based on mathematics.mathematics.

A relational database is a collection of relations A relational database is a collection of relations that, as a group, contain the data that describes that, as a group, contain the data that describes a particular business environment. a particular business environment.

Page 7: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-77

Relational TerminologyRelational Terminology

Relations - what we have been referring to Relations - what we have been referring to as simple linear files. Also called as simple linear files. Also called tablestables..

Row = record (files) = tuple (relation)Row = record (files) = tuple (relation)

Column = field (files) = attribute (relation)Column = field (files) = attribute (relation)

Page 8: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-88

Relational Database Relational Database TerminologyTerminology

Page 9: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-99

File / Relation: DifferencesFile / Relation: Differences

The columns of a relation can be arranged The columns of a relation can be arranged in any order without affecting the meaning in any order without affecting the meaning of the data. This is not true of a file. of the data. This is not true of a file.

The rows of a relation can be arranged in The rows of a relation can be arranged in any order, which is not true of a file.any order, which is not true of a file.

Page 10: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-1010

File / Relation: DifferencesFile / Relation: Differences

Every row/column position (a cell) can Every row/column position (a cell) can have only a single value, which is not have only a single value, which is not necessarily true in a file.necessarily true in a file.

No two rows of a relation are identical, No two rows of a relation are identical, which is not necessarily true in a file.which is not necessarily true in a file.

Page 11: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-1111

Primary KeyPrimary Key

A relation always has a unique A relation always has a unique primary primary keykey..

A primary key (also called “the key”) is an A primary key (also called “the key”) is an attribute or a group of attributes whose attribute or a group of attributes whose values are unique throughout all of the values are unique throughout all of the rows of the relation.rows of the relation.

Page 12: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-1212

Primary KeyPrimary Key

Page 13: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-1313

Primary KeyPrimary Key

The number of attributes involved in the The number of attributes involved in the primary key is always the minimum primary key is always the minimum number of attributes that provide the number of attributes that provide the uniqueness quality.uniqueness quality.

In the worst case, all of the relation’s In the worst case, all of the relation’s attributes combined could serve as the attributes combined could serve as the primary key.primary key.

Page 14: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-1414

Candidate KeyCandidate Key

If a relation has more than one attribute or If a relation has more than one attribute or minimum group of attributes that minimum group of attributes that represents a way of uniquely identifying represents a way of uniquely identifying the entities, then they are each called a the entities, then they are each called a candidate keycandidate key..

When there is more than one candidate When there is more than one candidate key, one of them must be chosen to be the key, one of them must be chosen to be the primary key of the relation.primary key of the relation.

Page 15: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-1515

Candidate KeyCandidate Key

Which candidate key Which candidate key to pick depends on to pick depends on the application using the application using the database.the database.

Alternate keyAlternate key is a is a candidate key that candidate key that was not chosen to be was not chosen to be the primary key of the the primary key of the relation.relation.

Page 16: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-1616

Foreign KeyForeign Key

An attribute or group of attributes that serves as the An attribute or group of attributes that serves as the primary key of one relation and also appears in another primary key of one relation and also appears in another relation (foreign key in this relation).relation (foreign key in this relation).

Page 17: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-1717

Foreign KeyForeign Key

Crucial in relational database, because the Crucial in relational database, because the foreign key is the mechanism that ties foreign key is the mechanism that ties relations together to represent unary, relations together to represent unary, binary, and ternary relationships.binary, and ternary relationships.

Foreign key attribute must have same Foreign key attribute must have same domain of valuesdomain of values as Primary key attribute as Primary key attribute in other relation.in other relation.

Page 18: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-1818

Domain of ValuesDomain of Values

Two attributes have the same domain of Two attributes have the same domain of values if the attributes have values of the values if the attributes have values of the same type.same type. e.g., Salesperson Number in SALESPERSON e.g., Salesperson Number in SALESPERSON

and in CUSTOMER - three digit whole and in CUSTOMER - three digit whole numbers that are the identifiers for numbers that are the identifiers for salespersons.salespersons.

Page 19: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-1919

Binary RelationshipsBinary Relationships

One-to-OneOne-to-One

One-to-ManyOne-to-Many

Many-to-ManyMany-to-Many

Page 20: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-2020

One-to-Many Binary One-to-Many Binary RelationshipRelationship

Salesperson Customer

The Salesperson Number The Salesperson Number foreign key in the foreign key in the CUSTOMER relation CUSTOMER relation effectively establishes the effectively establishes the one-to-many relationship one-to-many relationship between salespersons between salespersons and customers. and customers.

Page 21: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-2121

Foreign Key Can Be A Part of Foreign Key Can Be A Part of The Primary KeyThe Primary Key

Customer CustomerEmployee

Page 22: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-2222

General Hardware Co.General Hardware Co.

Page 23: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-2323

Many-to-Many Binary Many-to-Many Binary RelationshipRelationship

Salesperson Product

Page 24: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-2424

Many-to-Many RelationshipMany-to-Many Relationship

Page 25: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-2525

Intersection DataIntersection Data

Page 26: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-2626

Many-to-Many RelationshipMany-to-Many Relationship

Has its own relation in the database.Has its own relation in the database.

Can have its own attributes.Can have its own attributes.

It is a kind of entity -- an Associative EntityIt is a kind of entity -- an Associative Entity

Page 27: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-2727

SALES Relation (modified)SALES Relation (modified)

A Date attribute is A Date attribute is required if the data required if the data may be stored two or may be stored two or more times in a year.more times in a year.

A Time attribute is A Time attribute is required if the data required if the data may be stored more may be stored more than once in a day. than once in a day.

Page 28: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-2828

Unacceptable: Many-to-ManyUnacceptable: Many-to-Many

Page 29: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-2929

SALES Relation (without SALES Relation (without intersection data)intersection data)

Page 30: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-3030

One-to-One Binary One-to-One Binary RelationshipRelationship

Page 31: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-3131

General Hardware Co. General Hardware Co. including OFFICEincluding OFFICE

Page 32: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-3232

General Hardware Co. General Hardware Co. including OFFICEincluding OFFICE

Can SALESPERSON Can SALESPERSON and OFFICE be and OFFICE be combined into one combined into one relation?relation?

Page 33: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-3333

Data Retrieval from a Data Retrieval from a Relational DatabaseRelational Database

The discussion thus far has concentrated The discussion thus far has concentrated on:on: how a relational database is structuredhow a relational database is structured loading a database with dataloading a database with data

Let’s discuss the effort to retrieve the data Let’s discuss the effort to retrieve the data in a way that is helpful and beneficial to in a way that is helpful and beneficial to the business organization that built the the business organization that built the database.database.

Page 34: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-3434

Relational DBMSRelational DBMS

Have the ability to accept high level Have the ability to accept high level data data retrievalretrieval commands commands

Process the commands against the Process the commands against the database’s relationsdatabase’s relations

and return the desired data.and return the desired data.

Page 35: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-3535

The Relational Select The Relational Select OperatorOperator

Retrieves a horizontal slice of the relation.Retrieves a horizontal slice of the relation.

Select rows from the SALESPERSON Select rows from the SALESPERSON relation in which Salesperson Number = relation in which Salesperson Number = 204. 204.

The result of a relational operation will The result of a relational operation will always be a relation.always be a relation.

Page 36: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-3636

The Relational Project The Relational Project OperatorOperator

Retrieves a vertical slice of the relation.Retrieves a vertical slice of the relation.

Project the Salesperson Number and Project the Salesperson Number and Salesperson Name over the Salesperson Name over the SALESPERSON relation.SALESPERSON relation.

Page 37: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-3737

Extracting Data Across Extracting Data Across Multiple Relations: Data Multiple Relations: Data

IntegrationIntegration A DBMS must be able to store data A DBMS must be able to store data

nonredundantly while also providing a data nonredundantly while also providing a data integration facility.integration facility.

Relational DBMSs automate the cross-relation Relational DBMSs automate the cross-relation data extraction process in such a way that it data extraction process in such a way that it appears that the data in the relations is appears that the data in the relations is integrated while also remaining nonredundant. integrated while also remaining nonredundant.

Page 38: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-3838

Data IntegrationData Integration

The relational algebra The relational algebra JoinJoin command. command.

Join the SALESPERSON relation and the Join the SALESPERSON relation and the CUSTOMER relation, using the Salesperson CUSTOMER relation, using the Salesperson Number of each as the join fields. Number of each as the join fields.

Select rows from that result in which Customer Select rows from that result in which Customer Number = 1525. Number = 1525.

Project the Salesperson Name over that last Project the Salesperson Name over that last result.result.

Page 39: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-3939

TerminologyTerminology

Cartesian Product - comparing every Cartesian Product - comparing every possible combination of two sets, or two possible combination of two sets, or two relations.relations.

Equijoin - a join where two join field values Equijoin - a join where two join field values are identical.are identical.

Natural join - one of the two identical join Natural join - one of the two identical join columns is eliminated.columns is eliminated.

Page 40: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-4040

Good Reading BookstoresGood Reading Bookstores

Page 41: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-4141

World Music AssociationWorld Music Association

Page 42: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-4242

Lucky Rent-A-CarLucky Rent-A-Car

Page 43: Chapter 5 The Relational Database Model: Introduction Fundamentals of Database Management Systems, 2 nd ed. by Mark L. Gillenson, Ph.D. University of Memphis

5-5-4343

“Copyright 2004 John Wiley & Sons, Inc. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without express permission of the copyright owner is unlawful. Request for further information should be addressed to the Permissions Department, John Wiley & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages caused by the use of these programs or from the use of the information contained herein.”