ENTITY RELATIONSHIP DIAGRAM
ERD ----Entity Relationship Diagram
DATABASE ARCHITECTURE
ERD ----Entity Relationship Diagram
External level – concerned with the way individual users see the data
Conceptual level – can be regarded as a community user view a formal description of data of interest to the organization
Internal level – concerned with the way in which the data is actually stored
ERD ----Entity Relationship Diagram
conceptual design of the database.
ENTITY
ERD ----Entity Relationship Diagram
person, house) or it may be an object with conceptual existence (company ,job, university course)
ENTITY TYPE
attribute.
ENTITY SET
ERD ----Entity Relationship Diagram
entity type
Entity type
STUDENT
ATTRIBUTE
ERD ----Entity Relationship Diagram
their entities by single line.
EMPLOYEE
Ssn
Salary
Bdate
ERD ----Entity Relationship Diagram
SIMPLE ATTRIBUTE
attribute
Number)
COMPOSITE ATTRIBUTE
SINGLE VALUED ATTRIBUTE
ERD ----Entity Relationship Diagram
MULTI VALUED ATTRIBUTE
DERIVED ATTRIBUTE
STORED ATTRIBUTE
IDENTIFIER ATTRIBUTE OR KEY ATTRIBUTE
ERD ----Entity Relationship Diagram
|
|
|
|
|
|
Key
Superkey Candidate key Primary key Composite key Foreign key
The name of each primary key attribute is underlined.
SIMPLE KEY ATTRIBUTE
ERD ----Entity Relationship Diagram
STUDENT
Rollno
Name
FLIGHT
No-of- passengers
COMPOSITE KEY ATTRIBUTE
Date
Flightid
Flightno
CRITERIA FOR SELECTING IDENTIFIERS
ERD ----Entity Relationship Diagram
Some entities have more than one candidate identifier, so the following criteria should be used:
ERD ----Entity Relationship Diagram
Composite- hierarchy
ERD ----Entity Relationship Diagram
EMPLOYEE
Ssn
Salary
Bdate
Age
Phone- no
Address
City
State
Street- add
Street
Apartme
nt-no
multivalued
derived
Primary-key
stored
ERD ----Entity Relationship Diagram
Address-
Phone
Address
Phone
Composite and mutivalued attribute can also be nested arbitrarily to form complex key.
Areacode
Phoneno
State
Street-add
Street
Apartment no
City
Zip
SHOULD ‘ADDRESS’ ATTRIBUTE BE REPRESENTED AS SIMPLE ATTRIBUTE OR COMPOSITE?
ERD ----Entity Relationship Diagram
RELATIONSHIP TYPE
ERD ----Entity Relationship Diagram
there exists relationship
relationship and not attributes.
ERD ----Entity Relationship Diagram
are usually verbs.
EMPLOYEE
DEPARTMENT
WORKS- FOR
DEGREE OF A RELATIONSHIP
ERD ----Entity Relationship Diagram
SALESASSIST
PRODUCT
SELLS
CUSTOMER
Binary-relationship
It is the number of entity types that participate in a relationship
relationship type
relationship type
ERD ----Entity Relationship Diagram
more than once in different roles.
EMPLOYEE
SUPERVI SION
CARDINALITY CONSTRAINTS
ERD ----Entity Relationship Diagram
The number of instances of one entity that can or must be associated with each instance of another entity.
One to one (1:1) relationship One to many (1:m) relationship Many to one (m:1) relationship Many to many (m:n) relationship
ERD ----Entity Relationship Diagram
1
1
N
1
🞄
M
N
EMPLOYEE
DEPARTMENT
MANAGES 1
EMPLOYEE
DEPARTMENT
WORKS- FOR
EMPLOYEE
PROJECT
WORKS- ON
ROLE NAME
ERD ----Entity Relationship Diagram
Role name represents role that a participating entity from the entity type plays in the relationship.
supervisee.
PARITICIPATION CONSTRAINTS(OPTIONALITY)
ERD ----Entity Relationship Diagram
Specifies if existence of an entity depends on it being related to another entity via relationship.
TOTAL
PARTICIPATION
PARTIAL
ERD ----Entity Relationship Diagram
⚫
EMPLOYEE
DEPARTMENT
WORKS- FOR
1
N
department via WORKS-FOR
Cardinality + Optionality = multiplicity
ATTRIBUTE OF RELATIONSHIP TYPE
ERD ----Entity Relationship Diagram
EMPLOYEE
PROJECT
WORKS- ON
Hours
ERD ----Entity Relationship Diagram
one of the participating entity types.
EMPLOYEE
DEPARTMENT
MANAGES
Start-date
1
1
ERD ----Entity Relationship Diagram
ERD ----Entity Relationship Diagram
EMPLOYEE
DEPARTMENT
WORKS-
FOR
Start-date
1
N
ERD ----Entity Relationship Diagram
EMPLOYEE
PROJECT
WORKS- ON
Hours
N
M
WEAK ENTITY AND STRONG ENTITY
ERD ----Entity Relationship Diagram
Entity type that doesn’t have a key attribute on it’s own is called weak entity and the Regular entity types that have key value is called strong entities.
entity is called Identifying relationship.
Weak entities have always a total participating constraint because they cannot be identified without an owner entity.
ERD ----Entity Relationship Diagram
EMPLOYEE
DEPENDENTS
HAS
N
1
Dependent-
name
Employee
Relationship
ERD ----Entity Relationship Diagram
entities.
key(descriminator)
Partial key are set of attributes that can uniquely identify weak entities that are related to some owner entity
ERD ----Entity Relationship Diagram
relationship then it should not be modeled as complex attributes.
DESIGN CHOICE FOR ER CONCEPTUAL
ERD ----Entity Relationship Diagram
MODEL
Department
ERD ----Entity Relationship Diagram
EMPLOYEE
DEPARTMENT
WORKS- FOR
1
N
EMPLOYEE
DEPARTMENT
Employees
Can be refined to binary relation
ERD ----Entity Relationship Diagram
INSTRUCTOR
ERD ----Entity Relationship Diagram
INSTRUCTOR
COURSE
DEPARTMENT
STUDENT
Dept-name
COURSE
Can be refined as
Dept-name
Dept-name
STUDENT
WORKS
-FOR
REGISTE RED
BELONG
S-TO
ERD ----Entity Relationship Diagram
ALTERNATE NOTATIONS
ERD ----Entity Relationship Diagram
0<=min<=max and max>=1
Min>0 implies total particiaption Min=0 implies partial participation
CHOOSING BETWEEN BINARY AND TERNARY RELATIONSHIP
ERD ----Entity Relationship Diagram
PROJECT
SUPPLIER
PART
SUPPLY
Partno
Sname
Pname
Consider the ER diagram
Qty
ERD ----Entity Relationship Diagram
PROJECT
SUPPLIER
PART
SUPPLI ES
Partno
Sname
Pname
Qty
USES
CAN SUPPLY
ERD ----Entity Relationship Diagram
ERD ----Entity Relationship Diagram
weak entity type with three identifying relationship
ERD ----Entity Relationship Diagram
PROJECT
SUPPLIER
Partno
Sname
Pname
Qty
SS
SUPPLY
SPJ
1
N
N
SP
1 | |
PART | |
| |
1
N
DEALING WITH TERNARY RELATIONSHIPS
ERD ----Entity Relationship Diagram
PRODUCT
SALES- ASSISTANT
CUSTOMER
SELLS
SELLS
SELLS
ERD ----Entity Relationship Diagram
and both of them to the sale of a particular product.
PRODUCT
SALES-
ASSISSTANT
CUSTOMER
REQ UEST
MA
KES
SALE
INVO
LVES
REMOVING REDUNDANT RELATIONSHIP
ERD ----Entity Relationship Diagram
A relationship is redundant if it can be completely
represented by alternate transitive relationships
ERD ----Entity Relationship Diagram
CONFIRMING OPTIONALITY AND CARDINALITY OF RELATIONSHIP
ERD ----Entity Relationship Diagram
ERD ----Entity Relationship Diagram
scenarios.
relationships
ERD ----Entity Relationship Diagram
DERIVING THE RELATIONSHIP PARAMETERS
ERD ----Entity Relationship Diagram
1. One course is studied by how many students?
Answer = `zero or more'.
ERD ----Entity Relationship Diagram
2.One student studies how many courses?
Answer = `One'
relationship is 1, and is `mandatory'
CONSTRUCTING AN ER MODEL
ERD ----Entity Relationship Diagram
1.Identify entities
2.Remove duplicate entities
ERD ----Entity Relationship Diagram
3.List the attributes of each entity
ERD ----Entity Relationship Diagram
4.Mark the primary keys
ERD ----Entity Relationship Diagram
5.Define the relationships
6.Describe the cardinality and optionality of the relationships
ERD ----Entity Relationship Diagram
entities.
7.Remove redundant relationships
EXAMPLE
ERD ----Entity Relationship Diagram
⚫
“A Country Bus Company owns a number of busses. Each bus is allocated to a particular route, although some routes may have several busses. Each route passes through a number of towns. One or more drivers are allocated to each stage of a route, which corresponds to a journey through some or all of the towns on a route. Some of the towns have a garage where busses are kept and each of the busses are identified by the registration number and can carry different numbers of passengers, since the vehicles vary in size and can be single or double-decked. Each route is identified by a route number and information is available on the average number of passengers carried per day for each route. Drivers have an employee number, name ,
address, and sometimes a telephone number.”
ENTITIES
ERD ----Entity Relationship Diagram
their data.
RELATIONSHIPS
ERD ----Entity Relationship Diagram
Bus-route (m:1) - is serviced by
driver-stage (m:1) is allocated
stage-town (m:n) passes-through
ERD ----Entity Relationship Diagram
route-town (m:n) passes-through
ER DIAGRAM
ERD ----Entity Relationship Diagram
ATTRIBUTES
ERD ----Entity Relationship Diagram
ALTERNATIVE DIAGRAMATIC NOTATIONS FOR ER MODELS
ERD ----Entity Relationship Diagram
ERD ----Entity Relationship Diagram
ERD ----Entity Relationship Diagram
ERD ----Entity Relationship Diagram
ERD ----Entity Relationship Diagram
Displaying attributes
Symbols for entity type attribute and relationship
ERD ----Entity Relationship Diagram
Various (min, max) notations
CROW-FOOT NOTATION
ERD ----Entity Relationship Diagram
ENHANCED ER DIAGRAM
ERD ----Entity Relationship Diagram
The EER diagram includes the concepts of
Subclass and super class Specialization and Generalization Categorization
Attribute and relationship inheritance.
SUBCLASS SUPERCLASS AND INHERITANCE
ERD ----Entity Relationship Diagram
ERD ----Entity Relationship Diagram
Member entity of the subclass represents the same real world entity as some member of superclass and the Subclass entity has specific distinct role
ERD ----Entity Relationship Diagram
SPECIALIZATION
ERD ----Entity Relationship Diagram
Specialisation is a process of defining set of subclasses of an entity type.
ERD ----Entity Relationship Diagram
WHY INCLUDE SPECIALISATION CONCEPT?
ERD ----Entity Relationship Diagram
1. Certain attributes may apply only to specific entity.
to which the attributes apply.
2. Some relationship types may be participated in by only specific entities.
IN SPECIALISATION:
ERD ----Entity Relationship Diagram
1.Define a set of subclass of entity type
subclass
GENERALISATION
ERD ----Entity Relationship Diagram
The reverse process of abstraction in which we suppress the differences among several entity types, identify their common features and generalize them in to single super class of which original entity types are special subclasses.
CAR
Vehicle- id
Price
Licens
e-no
Max-
speed
No-of-
pass
TRUCK
Vehicle-id
Price
License
-no
Tonnage
No-of- axles
Licens e-no
ERD ----Entity Relationship Diagram
TRUCK
Tonnage
No-of-axles
CAR
Max- speed
No-of- pass
Vehicle- id
Price
VEHICLE
d
CONSTRAINTS ON SPECIALIZATION AND GENERALIZATION
ERD ----Entity Relationship Diagram
Predicate-defined subclasses
Attribute defined- specialization
User-defined subclass
ERD ----Entity Relationship Diagram
Generalization usually is total because the superclass is derived from the subclasses.
Example of disjoint partial Specialization
ERD ----Entity Relationship Diagram
SPECIALIZATION / GENERALIZATION HIERARCHIES, LATTICES
ERD ----Entity Relationship Diagram
Hierarchy has a constraint that every subclass has only one superclass (called single inheritance)
In a lattice, a subclass can be subclass of more than one superclass (called multiple inheritance)
ERD ----Entity Relationship Diagram
shared subclass
SPECIALIZATION / GENERALIZATION LATTICE
ERD ----Entity Relationship Diagram
EXAMPLE (UNIVERSITY)
CATEGORIES (UNION TYPES)
ERD ----Entity Relationship Diagram
Model a single super class /subclass relationship with more than one super class
Database for vehicle registration, vehicle owner can be a person, a bank (holding a lien on a vehicle) or a company.
the three super classes COMPANY, BANK, and PERSON
This is difference from shared subclass, which is subset of the intersection of its super classes (shared subclass member must exist in all of its super classes).
ERD ----Entity Relationship Diagram
CASE IN POINT: E-R MODEL FOR ONLINE SALES FOR BIGHIT VIDEO
ERD ----Entity Relationship Diagram
“ BigHit Video Inc. wants to create an information system for online sales of movies in both DVD and videotape format. People will be allowed to register as customers of the online site and to update their stored information. Informa-tion must be maintained about customers ’ shipping addresses, e-mail ad- dresses and credit cards. In a single sale, customers will be allowed to purchase any quantity of videos. The items in a single sale will be shipped to a single address and will have a single credit card charge A customer will be provided with a virtual shopping cart to store items to be purchased. As each item is selected, it is added to the shopping cart. When the customer finishes shopping, he will be directed to a checkout area where he can purchase all of the items in the shopping cart. At this time, payment and shipping information is entered. Once the sale is complete, the shopping cart will be deleted and the customer will be sent a receipt by e-mail.”
ERD ----Entity Relationship Diagram
ENTITY | ATTRIBUTE | CONSTRAINTS |
1.Customer | accountId | Key |
| lastName | Not null |
| firstName | |
| shippingAddresses | Multivalued composite with components name, street, city, state, zipcode |
| emailAddress | |
| creditCards | Multivalued composite with components type, accountNumber , expiration |
| password | Not null at least 6 characters |
IDENTIFY ENTITY AND ATTRIBUTES
ERD ----Entity Relationship Diagram
ENTITY | ATTRIBUTE | CONSTRAINTS |
2. Movie | Movieid | Key |
| Title | |
| Genre | |
| Media | Either “dvd” or “videotape” determines subclass |
3. DVD | Languages | Subclass of Movie |
| Videoformat | |
| Captioning | |
4. Videotape | Format | Subclass of Movie |
| Soundtrack | |
ERD ----Entity Relationship Diagram
ENTITY | ATTRIBUTE | CONSTRAINTS |
5. Sale | SaleId | Key |
| Totalcost | |
| DateSold | |
| CreditCard | Composite with components type, accountNumber , and expiration |
6. ShoppingCart | CartId | key |
| DateCreated | |
ERD ----Entity Relationship Diagram
RELATIONSHIPS
Relationsh ip Type | Entity Class | Entity Class | Cardinali ty Ratio | Attributes |
Purchases | Customer | Sale | one-to- many | |
Includes | Sale | Movie | many-to- many | quantity |
Selects | Customer | Shopping Cart | one-to- many | |
Includes | Movie | Shopping Cart | many-to- many | quantity |
ERD ----Entity Relationship Diagram
THANK YOU
ERD ----Entity Relationship Diagram