Entity/Relationship Modelling
Entity/Relationship Modelling
Entity/Relationship Modelling
Modelling:
• A database can be modeled as:
• a collection of entities,
• relationship among entities.
• Example
• In a University database we might have entities for Students, Modules and Lecturers. Students
might have attributes such as their ID, Name, and Course, and could have relationships with
Modules (enrolment) and Lecturers (tutor/tutee)
Entity/Relationship Diagrams
• E/R Models are often represented as E/R diagrams that
• Give a conceptual view of the database
Lecturer ID
• Are independent of the choice of DBMS
• Can identify some problems in a design Name Course
Tutors Student
Module Studies
Entities
• Entities represent objects or things of interest
• Physical things like students, lecturers, employees, products
• More abstract things like modules, orders, courses, projects
• Entities have
• A general type or class, such as Lecturer or Module
• Instances of that particular type, such as Steve Mills, Natasha Alechina are instances of
Lecturer
• Attributes (such as name, email address)
Diagramming Entities
Lecturer ID
Name Course
• In an E/R Diagram, an entity is usually drawn as a box with
rounded corners
Tutors Student
• The box is labelled with the name of the class of objects
represented by that entity
Module Studies
Attributes
• Attributes are facts, aspects, properties, or details about an entity
• Students have IDs, names, courses, addresses, …
• Modules have codes, titles, credit weights, levels, …
• Attributes have
• A name
• An associated entity
• Domains of possible values
• Values from the domain for each instance of the entity they are belong to
• Attribute types:
• Simple and composite attributes.
• Single-valued and multivalued attributes
• Example: multivalued attribute: phone_numbers
• Derived attributes
• Can be computed from other attributes
• Example: age, given date_of_birth
Diagramming Attributes
Lecturer ID
Module Studies
Relationships
• Relationships are an association between two or more entities
• Each Student takes several Modules
• Each Module is taught by a Lecturer
• Each Employee works for a single Department
• Relationships have
• A name
• A set of entities that participate in them
• A degree - the number of entities that participate (most have degree 2)
• A cardinality ratio
Mapping Cardinality Constraints
• Express the number of entities to which another entity can be associated via a relationship set.
• Most useful in describing binary relationship sets.
• For a binary relationship set the mapping cardinality must be one of the following types:
• One to one
• One to many
• Many to one
• Many to many
Mapping Cardinalities
Note: Some elements in A and B may not be mapped to any elements in the other set
Mapping Cardinalities
Note: Some elements in A and B may not be mapped to any elements in the other set
E-R Diagrams
Lecturer ID
• Relationships are links between two entities
Name Course
• The name is given in a diamond box
• The ends of the link show cardinality
Tutors Student
One Many
Module Studies
Removing M:M Relationships
Student
• Many to many relationships are difficult to represent
• We can split a many to many relationship into two one to Student
many relationships Has
In
Module
Module
Making E/R Models
• To make an E/R model you need to identify
• Enitities
• Attributes
• Relationships
• Cardinality ratios
• from a description
• General guidelines
• Since entities are things or objects they are often nouns in the description
• Attributes are facts or properties, and so are often nouns also
• Verbs often describe relationships between entities
Example - Entities
A university consists of a number of departments. Each department offers several courses. A
number of modules make up each course. Students enrol in a particular course and take modules
towards the completion of that course. Each module is taught by a lecturer from the appropriate
department, and each lecturer tutors a group of students
Example - Relationships
A university consists of a number of departments. Each department offers several courses. A number
of modules make up each course. Students enrol in a particular course and take modules towards
the completion of that course. Each module is taught by a lecturer from the appropriate department,
and each lecturer tutors a group of students
Example - E/R Diagram
Entities: Department, Course, Module, Lecturer, Student
Department
Student
Offers Department
Student
Offers Department
Student
Offers Department
Enrols In Student
Offers Department
Takes
Enrols In Student
Offers Department
Takes
Enrols In Student
Takes
Enrols In Student
Takes
Takes
• General guidelines
• Entities can have attributes but attributes have no smaller parts
• Entities can have relationships between them, but an attribute belongs to a single entity
Example - Entities/Attributes
• Entities or attributes:
• product • Products, suppliers, and addresses all have smaller parts so we
• description can make them entities
• price • The others have no smaller parts and belong to a single entity
• supplier
• address
• phone number
• name
• street address
• city
• postcode
Example - E/R Diagram
Street address
Price
Postcode
Example - Relationships
Name Supplier • Each product has a supplier
• Each product has a single supplier but there is nothing to
stop a supplier supplying many products
Phone number
• A many to one relationship
• Each supplier has an address
• A supplier has a single address
• It does not seem sensible for two different suppliers to
have the same address
• A one to one relationship
Example - E/R Diagram
Price
Description Product
Redundant Relationships c z
• We can merge the two entities that take part in a redundant
relationship together
• They become a single entity a x
• The new entity has all the attributes of the old one
b AB y
c z
Example - E/R Diagram
Price
Description Product
Has A
• Chen, IDE1FX, …