Entity Relationship Model
Entity Relationship Model
Model
• Introduction
• Key Definitions
• Entity, Entity Set and Entity Types
• Attributes
• Keys
• Nulls
• Relationships
Introduction
Data Models
• Data model is representation of
• things (or entities or classes) that are of importance to a system
• How the things relate to each other
• It is built and modified until it represents the system well enough to support a system model
• Data models are extended to become class diagrams in the Unified Modeling Language [UML] by
adding the behaviors of each entity to the model.
Introduction Continued…
• Entity
• a thing or object in the real world with an independent existence that can be differentiated from other objects
• Entity Relationship Model
• The entity relationship model (ERM) is a conceptual model that represents the information structure of a problem
domain in terms of entities and relationships
• Entity set
• A collection of entities of an entity type at a particular point of time
• Entity Type
• a collection of the entities having similar attributes
• Attribute
• The characteristics or properties of an entity
Key Definitions Continued..
• multivalued attributes
• attributes that have more than one value for each entity
• derived attributes
• Attributes that contain values calculated from other attributes
• Relationships
• The associations or interactions between entities; used to connect related information between tables
• Key
• An attribute or group of attributes whose values can be used to uniquely identify an individual entity in an
entity set.
• Primary Key (PK)
• A key in a relational database that is unique for each record
• foreign key (FK)
• An attribute in a table that references the primary key in another table OR it can be null
• composite key
• composed of two or more attributes, but it must be minimal
Entity, Entity Set and Entity Types
Entity
Recall Definition:
- A thing or object in the real world with an independent existence that can be differentiated from other objects
Database Definition
- A thing, person, place, unit, object or any item about which the data should be captured and stored.
Weak Entity
- An entity is considered weak if its existence depend on another entity. i.e, it cannot exist without a relationship with
another entity.
- Its primary key (Identity) is derived from the (identity) primary key of the parent entity
- Examples of Weak Entities:
- Spouse, in the COMPANY database, is a weak entity because its primary key is dependent on the Employee table.
Without a corresponding employee record, the spouse record would not exist.
- Address in a STUDENT database is a weak entity. Without a corresponding student record, the address record would
not exists.
- Account in a BANKING SERVICES database is a weak entity. Can you explain why this is so?
Classes of Entities Continued…
Strong Entity
- An entity is considered strong if it can exist apart from all of its related entities.
- Strong entities are also called Kernels: A table without a foreign key or a table that contains a foreign key that can contain
nulls
• The E-R Diagram represents the Entity type for an Entity set
• The Entity type is represented as a Singular noun of the Entity set in a rectangle as shown in the
diagram below:
Represented as
Entity type StudentNo
• Student 1
• Student 2
Entity Set STUDENT •
STUDENT FirstName
•
•
• Student N
Surname
DOB
Existence Dependency
• Defined as the existence of an entity, which is dependent on the existence of the related entity.
• Example:
• Weak Entities are Existence-dependent (Click on link to revisit Weak Entities)
Different Kinds of Entities
• Independent Entities
• Dependent Entities
• Characteristic Entities
Different Kinds of Entities Continued..
Independent Entities
• Also referred to as Kernels
Example:
• Strong Entities are Independent entities (Click on link to revisit Strong Entities)
Different Kinds of Entities Continued..
Dependent Entities
• Also referred to as Derived Entities. They depend on other entities for their meaning.
Characteristic Entities
• They provide more information about another table (Usually an independent entity)
STUDENT
Simple Attributes
• Drawn from the atomic value domains
• Also called as single-valued attributes
• (E.g. StudentNo, Firstname, Surname)
Composite Attributes
• Consist of a hierarchy of attributes Composite Attribute
STUDENT
• (E.g. Residential Address) Residential
StudentNo Address
Suburb
Multivalued Attributes
• Have a set of values for each entity type
• E.g. the different Accounts of a customer at the bank (Cheque, Investment, Credit Etc..)
NB: Note the kind of lines used in the E-R diagram to represent multivalued or derived attributes
Keys
Types of Keys
• Candidate key
• Composite key
• Primary Key
• Secondary Key
• Alternate Key
• Foreign Key
Keys Continued…
Candidate Key
• A candidate key is a simple or composite key that is unique and minimal.
• It is unique because no two rows in a table may have the same value at any time.
• It is minimal because every column is necessary in order to attain uniqueness.
• From the Student Records database, if the entity is: STUDENT(StudentNo, IDNo, FirstName, LastName, CourseID)
• Possible candidate keys are:
• StudentNo
• IDNo
• FirstName and LastName – Assuming no student has the same name as the other
• LastName and CourseID – Assuming that no two students with the same last name can register for the same
course
Keys Continued…
Composite Key
• A composite key is composed of two or more attributes, but it must be minimal.
• From the Candidate Keys in the previous slide, possible composite keys are:
• FirstName and LastName – Assuming no student has the same name as the other
• LastName and CourseID – Assuming that no two students with the same last name can register for the same course
Secondary Key
• A secondary key is an attribute used strictly for retrieval purposes (can be composite), for
example: Phone and Last Name
Alternate Key
• Alternate keys are all candidate keys not chosen as the primary key
Foreign Key
• A foreign key (FK) is an attribute in a table that references the primary key in another table OR it
can be null.
• Both foreign and primary keys must be of the same data type.
• In our example entity STUDENT(StudentNo, IDNo, FirstName, LastName, CourseID), the attribute
CourseID is a foreign key because it references the primary key CourseID in the entity COURSE.
Nulls
A null is a special symbol, independent of data type, which means either unknown or inapplicable.
• It does not mean zero or blank.
Features of null include:
• No data entry
• Not permitted in the primary key
• Should be avoided in other attributes
Can represent
• An unknown attribute value
• A known, but missing, attribute value
• A “not applicable” condition
• Can create problems when functions such as COUNT, AVERAGE and SUM are used
• Can create logical problems when relational tables are linked
Relationships
Types of Relationships
• One-to-Many (1:M)
• One-to-One (1:1)
• Many-to-Many (M:N)
• Unary (Recursive)
• Ternary
Relationships Continued…
Salary Name
Salary Budget
StartDate
Relational Schema
EMPLOYEE(EmpID, Name, Address, Salary)
PROJECT(Code, Name, Budget)
JOIN(EmpID, Code, StartDate)
Relationships Continued…
Unary Relationship
• also called recursive, is one in which a relationship exists between occurrences of the same entity
type
• The primary and foreign keys are the same, but they represent two entities with different roles
• separate column can be created that refers to the primary key of the same entity set
Supervisor
EmpID
Address
Supervisee
Salary
Relational Schema
EMPLOYEE(EmpID, Name, Address, Salary, SuperID)
Relationships Continued…
Ternary Relationship
• A relationship type that involves many to many relationships between three tables
Ternary Relationship
Code
SID
SUPPLIER M Supplies
N PROJECT
Name
Name
Address
Quantity Date
Budget
N
PART
Relational Schema
PartID Colour
SUPPLIER(SID, Name, Address)
PartName
PROJECT(Code, Name, Budget)
PART(PartID, Name, Colour)
SUPPLY(SID, Code, PartID, Quantity, Date)
Home Work