Week 3 Entity Attribute Relationship (EAR) Diagrams
Week 3 Entity Attribute Relationship (EAR) Diagrams
Week 3 Entity Attribute Relationship (EAR) Diagrams
(EAR) Diagrams
CIS 205
(EAR) Diagrams
• Database Design • Primary Key
• Entity • Ternary
• Attributes Relationships
• Null Values • Summary of ER
• Relationships Notation
• Well-Defined ERDs • Applying the
Concepts
• Visualizing ERDs
• Complete Example
Database Design
• Understand the problem domain. Analyze the
database requirements.
• Design a conceptual schema by creating an ER
diagram
• Design a logical schema
• Verify the design with the users and
other team members
Database Design
• Understand the problem domain. Analyze the
database requirements.
– Write a summary specification in English
– What do you need to store in the database?
– What queries and reports do you need to
generate?
Database Design
• Design a conceptual schema by creating an ER
diagram
– Identify entity types. Assign a singular noun to each entity
type.
– Identify relationships between entities. Use a meaningful
verb for a relationship name.
– Draw an ERD without attributes
– Assign attributes to entities & relationships
– Select the identifier (primary key) for each entity type
– Check ERD against database requirements
Database Design
• Design a logical schema
– Translate the ERD into a relational schema
– Determine the primary key of each relation
– Check normalization (at least 3NF) will discuss
later
– Create data dictionaries
– Do database prototyping & modify the design if
necessary
Entities in an EAR Diagram
• A “thing”; an object
– People, places,
tangible physical thing,
organizations, events,
concepts SSN
Name
Number
City State
StreetAddress City State Zip
Street Zip
Address
ApartmentNumber
– Symbol
Null Values
• A special value
• Can mean:
– Not applicable
– Unknown
• NULL Empty String
Relationships
• An association between entities
• Relationship Name
– meaningful verb
• Role name
– signifies the role that an entity plays in each relationship
instance
• Symbol
– diamond with the relationship name displayed within the
diamond
Relationships
• Degree of relationship
– the number of participating entities
• Binary Relationship
– degree of 2
• Ternary Relationship
– degree of 3
Relationships: Constraints
Each employee may work for one and only one department
1
N Department
Employee Works_For
Each employee may work for one and only one department
• Cardinality ratio ()
Structural
Constraint
• Participation (optional, mandatory)
Relationships: More Examples
• One-to-One (1:1)
– Each customer may have at most one account
– One account cannot be owned by more than one
customer 1
1 Account
Customer owns
• One-to-Many (1:N)
– Each customer can have many accounts
– Each account cannot be owned by more than one customer
N
1 Account
Customer owns
Relationships: More Examples
• Many-to-Many
– Each customer can have many accounts
– Each account must be owned by many customers
N
N Account
Customer owns
Relationships
• Basic Rules
– All entities & relationships must be connected
– Each entity must have at least one relationship
– All entity names must be unique
– Use a singular noun for an entity name and an attribute
name
– A relationship cannot be directly connected to another
relationship
– Use a meaningful verb for a relationship name whenever
possible
– Every entity must have at least one unique key (atomic or
concatenated)
Well-Defined ERDs
• Other Tips
– Do not show the primary key of one entity in either another
entity or a relationship
– Minimize line-crossing in ERDs
– List all attributes of an entity on one side for visual simplicity
– Arrange attributes left-to-right and top-down
– Underline entity identifiers
– The data you want to store in the DB must appear
somewhere in the ERD
– Create relationships with the most direct entity first
– Minimize redundant relationships
Primary Key
• Definition
– Uniqueness
• No two instances can have the same value in the
table
– Minimality
• There should not be any redundant attribute in a
key
Primary Key
Aname
R1 X
B# D#
B R3 D
Bname 1 1 Dname
Key Attribute
Weak Entity
Multivalued
Relationship
Composite Attribute
Identifying Relationship
Derived Attribute
Applying the Concepts
1. Gather & understand 5. Identify & draw
requirements cardinality constraints
2. Identify each entity 6. Assign attributes
3. Draw ERD without 7. Assign keys
attributes 8. Check model
4. Identify each
relationship