+ All Categories
Home > Documents > Database design, implementation, and management -chapter03

Database design, implementation, and management -chapter03

Date post: 26-May-2015
Category:
Upload: beni-krisbiantoro
View: 689 times
Download: 2 times
Share this document with a friend
Description:
Database Systems: Design, Implementation, and Management
Popular Tags:
71
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel
Transcript
Page 1: Database design, implementation, and management -chapter03

3

1

Chapter 3

The Relational Database Model

Database Systems:Design, Implementation, and Management,

Sixth Edition, Rob and Coronel

Page 2: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

2

In this chapter, you will learn:

•That the relational database model takes alogical view of data

•That the relational model’s basic componentsare entities, attributes, and relationshipsamong entities

•How entities and their attributes areorganized into tables

Page 3: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

3

In this chapter, you will learn (continued):

•About relational database operators, the datadictionary, and the system catalog

•How data redundancy is handled in therelational database model

•Why indexing is important

Page 4: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

4

A Logical View of Data•Relational model

–Enables us to view data logically rather thanphysically

–Reminds us of simpler file concept of datastorage

•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

Page 5: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

5

Tables and Their Characteristics

•Table: two-dimensional structure composed ofrows and columns

•Contains group of related entities an entityset

–Terms entity set and table are often usedinterchangeably

Page 6: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

6

Tables and Their Characteristics(continued)

•Table also called a relation because therelational model’s creator, Codd, used the termrelation as a synonym for table

•Think of a table as a persistent relation:

–A relation whose contents can be permanentlysaved for future use

Page 7: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

7

Characteristics of a Relational Table

Table 3.1

Page 8: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

8

STUDENT Table Attribute Values

Page 9: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

9

Keys

•Consists of one or more attributes thatdetermine other attributes

•Primary key (PK) is an attribute (or acombination of attributes) that uniquelyidentifies any given entity (row)

•Key’s role is based on determination

–If you know the value of attribute A, you canlook up (determine) the value of attribute B

Page 10: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

10

Student Classification

Page 11: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

11

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

Page 12: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

12

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 usingformulas

Page 13: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

13

Controlled Redundancy

•Makes the relational database work

•Tables within the database share commonattributes that enable us to link tablestogether

•Multiple occurrences of values in a table arenot redundant when they are required tomake the relationship work

•Redundancy is unnecessary duplication ofdata

Page 14: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

14

An Example of aSimple Relational Database

Page 15: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

15

The Relational Schema for theCH03_SaleCo Database

Page 16: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

16

Keys (continued)•Foreign key (FK)

–An attribute whose values match primary keyvalues in the related table

•Referential integrity

–FK contains a value that refers to an existingvalid tuple (row) in another relation

•Secondary key

–Key used strictly for data retrieval purposes

Page 17: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

17

Relational Database Keys

Page 18: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

18

Integrity Rules

Page 19: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

19

An Illustration of Integrity Rules

Page 20: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

20

A Dummy Variable Value Used as a Flag

Page 21: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

21

Relational Database Operators

•Relational algebra

–Defines theoretical way of manipulating tablecontents using relational operators:

•SELECT

•PROJECT

•JOIN

•INTERSECT

–Use of relational algebra operators on existingtables (relations) produces new relations

•UNION•DIFFERENCE•PRODUCT•DIVIDE

Page 22: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

22

Relational Algebra Operators (continued)

•Union:

–Combines all rows from two tables, excludingduplicate rows

–Tables must have the same attributecharacteristics

•Intersect:

–Yields only the rows that appear in both tables

Page 23: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

23

Union

Page 24: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

24

Intersect

Page 25: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

25

Relational Algebra Operators (continued)

•Difference

–Yields all rows in one table not found in theother table—that is, it subtracts one table fromthe other

•Product

–Yields all possible pairs of rows from twotables

•Also known as the Cartesian product

Page 26: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

26

Difference

Page 27: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

27

Product

Page 28: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

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 aspecified criterion

–Yields a horizontal subset of a table

•Project–Yields all values for selected attributes–Yields a vertical subset of a table

Page 29: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

29

Select

Page 30: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

30

Project

Page 31: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

31

Relational Algebra Operators (continued)

•Join

–Allows us to combine information from two ormore tables

–Real power behind the relational database,allowing the use of independent tables linkedby common attributes

Page 32: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

32

Two Tables That Will Be Usedin Join Illustrations

Page 33: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

33

Natural Join

• Links tables by selecting only rows withcommon values in their common attribute(s)

• Result of a three-stage process:1. PRODUCT of the tables is created2. SELECT is performed on Step 1 output to

yield only the rows for which theAGENT_CODE values are equal• Common column(s) are called join column(s)

3. PROJECT is performed on Step 2 results toyield a single copy of each attribute, therebyeliminating duplicate columns

Page 34: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

34

Natural Join, Step 1: PRODUCT

Page 35: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

35

Natural Join, Step 2: SELECT

Page 36: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

36

Natural Join, Step 3: PROJECT

Page 37: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

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 unmatchedrow

Page 38: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

38

Natural Join (continued)

•The column on which we made the JOIN—thatis, AGENT_CODE—occurs only once in thenew table

•If the same AGENT_CODE were to occurseveral times in the AGENT table,

–a customer would be listed for each match

Page 39: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

39

Other Forms of Join•Equijoin

–Links tables on the basis of an equalitycondition that compares specified columns ofeach table

–Outcome does not eliminate duplicatecolumns

–Condition or criterion to join tables must beexplicitly defined

–Takes its name from the equality comparisonoperator (=) used in the condition

•Theta join–If any other comparison operator is used

Page 40: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

40

Outer Join

•Matched pairs are retained and anyunmatched values in other table are left null

•In outer join for tables CUSTOMER andAGENT, two scenarios are possible:–Left outer join

•Yields all rows in CUSTOMER table, includingthose that do not have a matching value in theAGENT table

–Right outer join•Yields all rows in AGENT table, including those

that do not have matching values in theCUSTOMER table

Page 41: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

41

Left Outer Join

Page 42: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

42

Right Outer Join

Page 43: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

43

Divide

•DIVIDE requires the use of one single-columntable and one two-column table

Page 44: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

44

DIVIDE

Page 45: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

45

The Data Dictionaryand System Catalog

•Data dictionary–Used to provide detailed accounting of all

tables found within the user/designer-createddatabase

–Contains (at least) all the attribute names andcharacteristics for each table in the system

–Contains metadata—data about data–Sometimes described as “the database

designer’s database”because it records thedesign decisions about tables and theirstructures

Page 46: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

46

A Sample Data Dictionary

Page 47: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

47

The Data Dictionaryand the System Catalog (continued)

•System catalog

–Contains metadata

–Detailed system data dictionary that describesall objects within the database

–Terms “system catalog”and “data dictionary”are often used interchangeably

–Can be queried just like any user/designer-created table

Page 48: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

48

Relationships within theRelational 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 dataredundancies

•1:1 relationship–Should be rare in any relational database

design

Page 49: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

49

The 1:1 Relationship

•Relational database norm

•Found in any database environment

•One entity can be related to only one otherentity, and vice versa

•Often means that entity components were notdefined properly

•Could indicate that two entities actuallybelong in the same table

•Sometimes 1:1 relationships are appropriate

Page 50: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

50

The 1:1 Relationship BetweenPROFESSOR and DEPARTMENT

Page 51: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

51

The Implemented 1:1 Relationship BetweenPROFESSOR and DEPARTMENT

Page 52: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

52

The 1:M RelationshipBetween PAINTER and PAINTING

Page 53: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

53

The Implemented 1:M RelationshipBetween PAINTER and PAINTING

Page 54: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

54

The 1:M RelationshipBetween COURSE and CLASS

Page 55: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

55

The Implemented 1:M RelationshipBetween COURSE and CLASS

Page 56: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

56

The M:N Relationship

•Can be implemented by breaking it up toproduce a set of 1:M relationships

•Can avoid problems inherent to M:Nrelationship by creating a composite entity orbridge entity

Page 57: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

57

The ERD’s M:N RelationshipBetween STUDENT and CLASS

Page 58: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

58

Sample Student Enrollment Data

Page 59: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

59

The M:N RelationshipBetween STUDENT and CLASS

Page 60: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

60

Linking Table

•Implementation of a composite entity

•Yields required M:N to 1:M conversion

•Composite entity table must contain at leastthe primary keys of original tables

•Linking table contains multiple occurrences ofthe foreign key values

•Additional attributes may be assigned asneeded

Page 61: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

61

Converting the M:N Relationshipinto Two 1:M Relationships

Page 62: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

62

Changing the M:N Relationshipto Two 1:M Relationships

Page 63: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

63

The Expanded Entity Relationship Model

Page 64: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

64

The Relational Schema for theCh03_TinyCollege Database

Page 65: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

65

Data Redundancy Revisited

•Data redundancy leads to data anomalies

–Such anomalies can destroy databaseeffectiveness

•Foreign keys

–Control data redundancies by using commonattributes shared by tables

–Crucial to exercising data redundancy control

•Sometimes, data redundancy is necessary

Page 66: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

66

A Small Invoicing System

Page 67: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

67

The Relational Schemafor the Invoicing System

Page 68: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

68

Indexes•Arrangement used to logically access rows in

a table

•Index key–Index’s reference point

–Points to data location identified by the key

•Unique index–Index in which the index key can only have

one pointer value (row) associated with it

•Each index is associated with only one table

Page 69: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

69

Components of an Index

Page 70: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

70

Summary•Entities are basic building blocks of a

relational database•Entity set is a grouping of related entities,

stored in a table•Keys define functional dependencies

–Superkey–Candidate key–Primary key–Secondary key–Foreign key

Page 71: Database design, implementation, and management -chapter03

Database Systems: Design, Implementation, & Management, 6th Edition, Rob & Coronel

3

71

Summary (continued)

•Primary key uniquely identifies attributes–Can link tables by using controlled redundancy

•Relational databases classified according todegree to which they support relational algebrafunctions

•Relationships between entities are representedby entity relationship models

•Data retrieval speed can be increaseddramatically by using indexes


Recommended