things are bad. children no longer obey their parents and everyone is writing a book. -- marcus...

46
Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Upload: augustine-boone

Post on 24-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Things are bad. Children no longer obey their parents and everyone is writing a book.

-- Marcus Tillius Cicero

Page 2: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Entity Relationship Diagram

What Is It? A graphical diagram representing

the data relationships in a problem area

Often referred to as E/RD

Page 3: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Entity Relation Diagram

Student

ClassEnrolls in

S_No

S_Name

C_No

C_Name

Entities

Relationship

Attribute

Attribute

Key

Key

Page 4: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

IDEF1X Diagram

Supplier Parts

Supplier No (FK)Part No (FK)

Qty

Parts

Part No

Part NameColorWeightCity

Supplier

Supplier No

Supplier NameStatusCity This is an entity

This is a relation, in this case, a 1:m

An associative entity

Page 5: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Entity-Relationship Diagram Consists of

Entities Relationships Keys Attributes

Is not necessarily Normalized

Page 6: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Entity Any distinguishable person, place,

thing, event, or concept about which information is kept.

An Entity has attributes of interest that you want to store.

Entity Instance – A single occurrence of an entity.

Page 7: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Naming Entities Be careful naming entities, consider: To a dog breeder Collie may be an entity To a veterinarian Large Dog may be an

entity To a pet shop Dog may be an entity To a rental firm Pet may be an entity The trick is to know whether you have found

an entity or an instance

Page 8: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Entity Instance Instance means a single member

of an entity; a member of the set. It might eventually be defined as a

row in a table. In relational set theory, it would be

called a tuple.

Page 9: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Associative Entity An Associative or Intersection

Entity is a juncture between two entities

They are generally created as the result of a many to many relationship

Page 10: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Entities Entities are represented as boxes Square cornered boxes represent

independent entities Rounded cornered boxes represent

dependent entities More on this later

Page 11: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Example of Entities

StudentStudent Number

Student Name

Street Address

City

State

Zip Code

Phone Number

Birth Date

Entity Title

Entity Box

Primary Key

Attributes

Page 12: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Relationship A connection between two entities

Page 13: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Relationships Relationships are represented as lines They are two sided, theyconnect two

entities They have names The connection between entities and

relationships can be stated as sentences, which are the business rule

One Instructor Teaches Many Classes

Page 14: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Types of Relationships Identifying Relationships Non-Identifying Relationships Recursive Relationships

Page 15: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Identifying Relationship It is necessary to know the parent

to uniquely identify the child The Child will be an associative

entity

Page 16: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Non-identifying Relationship

It is not needed to know the Parent to uniquely define the child

The Child will not be an associative entity (at least in this relationship)

Page 17: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Recursive Relationship A relation points an entity back to

itself The key of the parent becomes an

attribute of the child A recursive relationship is non-

identifying

Page 18: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

More about Entities Entities can exist in two forms

Independent Entity Either Entity can exist without a

relationship to the other Dependent Entity

A Dependent Entity must be tied to one or more Independent Entities

Page 19: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

More About Relationships Relationships can be:

Identifying Relationships Ties an Independent Entity and a

Dependent Entity together Non-Identifying Relationships

Ties two (or more) Independent Entities together

Page 20: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

E/R examples A TEAM HAS many PLAYERS

Team Players

HAS

Page 21: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

E/R Examples A Plane-Flight transports many

Passengers

Plane-Fight Passengers

Transports

Page 22: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

E/R Examples A House is Owned by 1 Owner

House Owner

Owned

Page 23: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

E/R Examples Many Salespeople Sell many Products.

Salesperson

Product

Sell

Page 24: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Attribute A property of an Entity It is a distinct characteristic for

which data is maintained An Entity must have at least one

attribute or it does not exist

Page 25: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Attributes Attributes are fields They describe the entity They can be data attributes (non-

key) or key attributes

Page 26: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Keys

Primary Key – An attribute or group of attributes that has been chosen as the unique identifier of the entity

Primary Key Attribute – A attribute that, either by itself or in combination with other primary key attributes will form the primary key

Non-key Attribute – An attribute that has not been chosen as a part of the primary key of the entity

Candidate Key – An attribute or group of attributes that might be chosen as a primary key

Foreign Key – Primary Key from another entity, contributed by a relationship.

Page 27: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Key Selection Employee

Employee Number Employee Name Employee Sex Employee Hire Date Social Security Number Employee Birth Date Employee Bonus Amount

Page 28: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Key Selection Rules Find an attribute that will not change its

value of the life of each entity instance Look for a reasonably small key Avoid ‘Intelligent’ keys where the

structure of the key indicates groupings, locations, classification, dates, etc.

Consider substituting a single attribute surrogate key for a large composite key

Page 29: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Entities with AttributesEmployee

Employee Number

Employee NameEmployee SexEmployee Hire DateSocial Security NumberEmployee Birth DateEmployee Bonus Amount

Primary KeyArea

Data AttributeArea

Page 30: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Identity Relationship A relationship in which the primary

key of the parent entity becomes part of the primary key of the child entity

Page 31: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Identity Relationships

Parent ChildParent Key

Parent Key (fk)

Child Key

Page 32: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Non-Identity Relationship A relationship where the primary

key of the parent entity is placed in the data area of the child entity.

In non-identifying relationships the child may be existence-dependent on the parent, but is not identification-dependent on the parent.

Page 33: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Non Identifying Relationship

Parent ChildParent Key

Child Key

Parent Key (fk)

Page 34: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Entities Independent Entity – An entity that

does not depend on any other for its identification. Represented by a square cornered box.

Dependent Entity – An entity that depends on one or more other entities for its identification. Represented by a rounded corner box.

Page 35: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

1:1 RelationshipsEmployee Car

Kurt Yugo

Brian Mustang

TonyaRanger

Scott Jeep

NancyCamry

Assigned

Page 36: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

1:n RelationshipsCustomer

Video

Jack

Janet

Tim

Star Wars

Monty Python and the Holy Grail

Speed

Sleepless in Seattle

Casablanca

Silence of the Lambs

Rents

Page 37: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

N:M RelationshipsCourse

Student

Sara

Jesse

Sam

Java Programming

Accounting I

English 101

Physics for Dummies

Enrolls In

Page 38: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Excercises Try and draw the E/RD’s for the

following exercises Some exercises may build on what

was done in previous exercises.

Page 39: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Exercise #1 Customers come into the video

store and rent movies. Customers must be in the store system. This system assigns them a unique identifier. When we sign them up we get their name, address, and phone number.

Page 40: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Exercise #2 We have many movies in the store.

We try and keep a large number of the most popular movies and a smaller number of less popular movies. Each VHS or DVD copy is individually identified. We will rent these copies many times through out the year.

Page 41: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Exercise #3 When a movie is rented out, it is

due back in three days. We need to know who has the movie rented out.

Page 42: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Exercise #4 For each movie, we need to know

the name, rating, and rental rate. For each copy of the movie we

need to know its general condition and the remaining rentals we will use that copy for.

Page 43: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Exercise #5 We have employees at each store.

We know the employee’s name, address, hire date and salary.

These employees are involved in the rental process. We want to know which employee is involved in each rental event.

Page 44: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Exercise #6 When a movie is rented, we need

to track when the movie was rented, which copy of the movie was rented, what customer rented it, and what employee is involved.

Page 45: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

What You Should Know What the different kinds of entities

are. What the different relationships

are. What a primary key is and how to

select it. How to draw simple E/RD’s.

Page 46: Things are bad. Children no longer obey their parents and everyone is writing a book. -- Marcus Tillius Cicero

Assignment Review Chapter 5. Make sure you understand how to

create the E/RD for the exercises.