things are bad. children no longer obey their parents and everyone is writing a book. -- marcus...
TRANSCRIPT
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
Entity Relation Diagram
Student
ClassEnrolls in
S_No
S_Name
C_No
C_Name
Entities
Relationship
Attribute
Attribute
Key
Key
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
Entity-Relationship Diagram Consists of
Entities Relationships Keys Attributes
Is not necessarily Normalized
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.
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
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.
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
Entities Entities are represented as boxes Square cornered boxes represent
independent entities Rounded cornered boxes represent
dependent entities More on this later
Example of Entities
StudentStudent Number
Student Name
Street Address
City
State
Zip Code
Phone Number
Birth Date
Entity Title
Entity Box
Primary Key
Attributes
Relationship A connection between two entities
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
Types of Relationships Identifying Relationships Non-Identifying Relationships Recursive Relationships
Identifying Relationship It is necessary to know the parent
to uniquely identify the child The Child will be an associative
entity
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)
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
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
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
E/R examples A TEAM HAS many PLAYERS
Team Players
HAS
E/R Examples A Plane-Flight transports many
Passengers
Plane-Fight Passengers
Transports
E/R Examples A House is Owned by 1 Owner
House Owner
Owned
E/R Examples Many Salespeople Sell many Products.
Salesperson
Product
Sell
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
Attributes Attributes are fields They describe the entity They can be data attributes (non-
key) or key attributes
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.
Key Selection Employee
Employee Number Employee Name Employee Sex Employee Hire Date Social Security Number Employee Birth Date Employee Bonus Amount
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
Entities with AttributesEmployee
Employee Number
Employee NameEmployee SexEmployee Hire DateSocial Security NumberEmployee Birth DateEmployee Bonus Amount
Primary KeyArea
Data AttributeArea
Identity Relationship A relationship in which the primary
key of the parent entity becomes part of the primary key of the child entity
Identity Relationships
Parent ChildParent Key
Parent Key (fk)
Child Key
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.
Non Identifying Relationship
Parent ChildParent Key
Child Key
Parent Key (fk)
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.
1:1 RelationshipsEmployee Car
Kurt Yugo
Brian Mustang
TonyaRanger
Scott Jeep
NancyCamry
Assigned
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
N:M RelationshipsCourse
Student
Sara
Jesse
Sam
Java Programming
Accounting I
English 101
Physics for Dummies
Enrolls In
Excercises Try and draw the E/RD’s for the
following exercises Some exercises may build on what
was done in previous exercises.
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.
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.
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.
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.
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.
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.
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.
Assignment Review Chapter 5. Make sure you understand how to
create the E/RD for the exercises.