23
Chapter 2: Data Models 1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data Models Instructor’s name and information goes here Please see the notes pages for more information.

Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

Embed Size (px)

Citation preview

Page 1: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

Chapter 2: Data Models 1

Principles of Database SystemsWith Internet and Java Applications

Today’s Topic

Chapter 2: Representing Information with Data Models

Instructor’s name and information goes here

Please see the notes pages for more information.

Page 2: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

2

Chapter 2, Representing Information with Data Models Entity Relationship (ER) Model

– high-level, conceptual data model Specify conceptual schema

– conceptual database design Identify the data requirements of users and

detailed descriptions of data types, relationships and constraints.

Concentrate on specifying the properties of the data, not storage.

Page 3: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

3

An Example of ER Modeling Company database

– Department• name, number, manager (employee), start date

of manager– Projects controlled by department

• name, number, single location– Employees

• name, ssn, address, salary, sex, birthdate• assigned to department, several projects

– Dependents of employees

Page 4: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

4

Principals of ER Modeling

Entities and classes– Entity, a thing in the real world– Entity Class, the structure of a collection of

similar entities Attributes

– Attribute, a property of an entity– Each entity has a value for each of its attributes

Types of attributes– simple vs. composite, single-valued vs. multi-

valued, stored vs. derived– domains of attributes

Page 5: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

5

Relationships Between Entities Relationship type defines a set of

associations among given types. Relationsip Instances are particular

relationships among objects. Examples of relationship types in company

database– Manages: 1:1 between employee and department– Works-for: 1:N between department and employee– Controls: 1:N between department and project

Page 6: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

6

Relationships, Roles, and Structural Constraints

Roles are attributes that signify the function of a particular entity (type) in a relationship– Employee manages department– Department is managed by employee– Employee works-for department– Department has employees who work for it

Constraints can be – cardinality

• Each department can have no more than one manager

– participation• Each department must have a manager

Page 7: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

7

ER schema diagram for Company

1

Employee

1

Dependent

1

M

DependsOn

Manages

WorksFor

Project

Controls

Department

WorksOn

Supervises

M

Page 8: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

8

Entity Classes for BigHit Video

Entity Class DescriptionCustomer A customer of the businessVideotape An item in the rental inventoryEmployee A person who works in one or more

storesPayStatement A record of the wages paid to an

employeeTimeCard A record of a block of time worked by an

employee at a storeStore One of the retail outlets of BigHit VideoRental The rental of a videotape by a customer

for a specific period and costPurchaseOrder A request to purchase an itemVendor A company that sells items to BigHit

Video

Page 9: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

9

Sample Attribute Specifications

Attribute Type Domain of values Descriptiontitle string unbounded The title of an itemlastName string 30 characters The last name of a personfirstName string 30 characters The first name of a personssn string 10 digits A social security numberaccountId number 4 byte integer The identifier of a customer

accountotherUsers set set of strings of 30 characters Names of other people

authorized to use thisaccount

numberRentals

number 4 byte integer Number of rentals for acustomer

address composite 2 strings of 30 characters, onestring of 2 characters, and onestring of 9 digits.

An address that consists of astreet, city, state and zipcode

Page 10: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

10

Entity Classes, Attributes and Constraints

Class Attribute Constraints or furtherdescription

Customer accountId keylastName not nullfirstNameaddressotherUsersnumberRentals derived

Videotape videotapeId keytitle not nullgenre

PayStatement datePaidhoursWorkedamountPaid

Page 11: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

11

Entities, instances of classes

customerId

lastName firstName address otherUsers numberRentals

street city state zipcode101 Block Jane 1010

Main St.Apopka FL 30458 Joe Block,

Greg Jones3

102 Hamilton Cherry 3230Dade St.

DadeCity

FL 30555 1

103 Harrison Kate 103DoddHall

Apopka FL 30457 0

104 Breaux Carroll 76 MainSt.

Apopka FL 30458 JudyBreaux,CyrusLambeaux,Jean Deaux

2

Page 12: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

12

Relationships Between Entities Relationship type defines a set of

associations among given types. Relationship Instances are particular

relationships among objects. Examples of relationship types in company

database– Manages: 1:1 between employee and department– Works-for: 1:N between department and employee– Controls: 1:N between department and project

Page 13: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

13

Relationships, Roles, and Structural Constraints

Roles are attributes that signify the function of a particular entity (type) in a relationship– Employee manages department– Employee works-for department

Constraints can be – cardinality

• Each department can have no more than one manager

– participation• Each department must have a manager

Page 14: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

14

Relationship Types and Instances Marriage relationship type

– Person related to Person– One person has the role of “wife” one has the role

of “husband”– Relationship type may have one or more attributes

• e.g. weddingDate Marriage relationship (instance)

– Jane Block is married to Joe Block (relationship)– Jane Block is the wife of Joe Block (role)– Joe Block is the husband of Jane Block (role)

Parent-child relationship type– A person may have zero or more children

Page 15: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

15

Relationships are always one-to-one A relationship is an instance These pictures are sets of instances

101

123

145

90987

99787

Videotape(videotapeId)

Rents

101

102

103

104

Customer(accountId)

101

123

145

90987

99787

Videotape(videotapeId)

PreviouslyRented

101

102

103

104

Customer(accountId)

Page 16: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

16

Find the Entities, Attributes and Relationships

BigHit VideoRental Receipt

Account Id: 101 Videotape Id: 90987 date: January 9, 1999 cost: $2.99Jane Block1010 Main St.Apopka, FL 30458

Elizabeth date due: January 11, 1999

Page 17: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

17

ER schema diagram for BigHit Video

1

lastName accountIdfirstName

numberRentals

balance

otherUsers

RelationshipType

EntityClass

Attribute

KeyAttribute

DerivedAttribute

CompositeAttribute

Multi-valuedAttribute

CardinalityConstraint

Customer

address

zipcode

statecity

street

MVideotapeRents

dateRented

costdateDue

videotapeId title genre

dateAcquired

length

rating

Page 18: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

18

Keys of entities A key is a set of attributes that uniquely

identify one entity within the class– accountId is a key for Customer– may be multiple attributes (examples follow)

A key constraint specifies a restriction on a set of entities– no 2 entities in the set may have the same values

for the key– an attempt to add a new entity with the same key

as another entity is not allowed

Page 19: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

19

Weak Entity Classes An entity class that has no key is a weak

entity class– A weak entity is identified by its relationships– The relationships are called identifying

relationships A weak entity may exist only if it is related to

other entities by its identifying relationships Examples

– Rental– TimeCard

Page 20: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

20

More facets of ER diagrams

PersonIs

ChildOf

M

1..2

parent

child

ssn

IsMarried

To

1

1

wife

husband

IsParentOf

AlternativeRelationshipType Name

RoleName

Page 21: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

21

Treating Rents as an entity class Should Rental be an entity class?

– instead of relationship type Rents A rental entity represents the possession of a

videotape by a customer

Videotape1

Customer1

costdateDue dateRented

Has Rental1

MHas

Page 22: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

22

Subtleties in Meaning of Purchase Order

VideotapeM

PurchaseOrder

quantity

MOrders

movieId

Supplier

1PurchaseOrder quantity

M

dateId

title Movie

Orders

M

1

BuysFrom

PurchaseOrderDetailHas

M

1

unitCost

addressname

lineNumber

VideotapeIs

CopyOf

dateAcquired

1 M

genre

videoId

dateAcquired

length rating

Page 23: Chapter 2: Data Models1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 2: Representing Information with Data

23

Summary of Chapter 2 Information system is a repository of facts about an

organization– Discovery of the structure of information

Data model specifies the structure and meaning of data– Limitations on systems created by faulty models– Options and alternatives are exposed by the process– Forms the basis for system development– Provides basis for agreement between developer and user

Entity-relationship modeling – Entity is a thing, entity class is a set of things– Relationship type represents the possibility that two entities

are related in a specific way– E-R diagram is an appropriate way to represent a data model

E-R diagrams are the deliverables of the initial phase of information system development