0% found this document useful (0 votes)
7 views33 pages

Lecture 3IS099

Uploaded by

kimarodamian123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views33 pages

Lecture 3IS099

Uploaded by

kimarodamian123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 33

Management of Database Systems

IS 099
Lecture 3: Basic Entity Relationship Modeling
Lecture Outline
• Data Modeling
• Entity-relationship model
• Features of ER-model
• Intro to ERDs
• Entity and Attribute
• Entity set
• Strong and weak entity
• Attribute types
• Key attribute
Data modeling
A model is a simplified version of real-life, complex objects.

Databases are complex, and data modeling is a tool to represent the various components and their relationships.

Data model is a collection of conceptual tools for describing data, data relationships, data semantics, and
consistency constraints.
 Define how data is connected to each other and how they are processed and stored inside the system.
 Describes/underlies the logical structure of a database
Main types of data model includes:
- Entity-relationship (E-R) model
- Relational model

Other models:
- Object-oriented model
- Semi-structured data models
- Older models: network model and hierarchical model
The entity - relationship (E-R) model is a very popular modeling tool among many such tools available today.
Entity-relationship model
• Entity-relationship (ER) modeling is a data modeling technique used in software engineering to produce a
conceptual data model of a information system.
• The (ER) data model is based on a perception of a real world
that consists of a collection of basic objects (entities), and relationships
among these objects. And their graphical representation in a database.
• The main components of ER model are: entity sets, relationship sets
and attributes.
• It describes the database structure with the help of diagrams known as Entity-Relationship Diagrams or ER
diagrams or ERDs.
About- ER model
The main features:
• Entity relationship model is a high level conceptual model
• This model is used to define the data elements and relationship for a specified system
• It is widely used to develop an initial design of a database
• It provides a set of useful concepts that make it convenient to develop a very simple and easy-to-design view of
data for the database.
• In ER modeling, the database structure is portrayed as a diagram called an entity-relationship diagram.
• It describes data as a collection of entities, relationships and attributes.
Introduction to ER diagrams
• Is a visual representation of different data using conventions that describe how these data are related to each other.
- An ER diagram shows the relationship among entity sets.
- It is a design or blueprint of a database that can later be

implemented as a database.
Entity
• An entity is something that exists by itself, and can be easily identifiable.
• Entity: Real-world object distinguishable from other objects. An entity is described using a set of attributes.
- For example, in a school database, students, teachers, classes, and courses offered can be considered as entities.
- Others are person, book, customer, bank account etc.
- All these entities have some attributes or properties that give them their identity.
• An entity is represented in the E-R diagram by means of
rectangles. Rectangles are named with the entity set they represent.
Note: Use singular names rather than plurals, because entity apply for each individual entity
• Example of entities
- Person: EMPLOYEE, STUDENT PATIENT
- Place: STORE, WAREHOUSE
- Object: MACHINE, PRODUCT, CAR
- Event: SALE, REGISTRATION, RENEWAL
- Concept: ACCOUNT, COURSE
Entity set
• The collection of entities of the same kind.
- An entity set may contain entities sharing same attributes, but have their own values for each attribute.
- For example, a Student set may contain all the students of a school; likewise a Teachers set may contain all the
teachers of a school from all faculties.
- Another example: a company hiring hundreds of employees may want to store similar information.
• Entity sets need not be disjoint.
• Each entity set has a key ( a set of attributes uniquely identifying an entity).
Weak entity
• A weak entity is an entity that depends on the existence of another entity. For example, a room can only exist in a
building, or a bank account can’t be identified without knowing the bank.
• In more technical terms it can defined as an entity that
cannot be identified by its own attributes.
• A weak entity can be identified uniquely only by considering
the primary key of the parent/owner entity. In this case, the parent
entity is a strong entity.
• Therefore, it must use a foreign key in conjunction with its
attributes to create a primary key. The foreign key is typically a primary key of an entity it is related to.
Key attribute
• Key is an attribute or collection of attributes that uniquely identifies an entity among entity set.
• Keys are very important in relational database. They are used to establish and identify relation between tables.
Thus, key attribute represents a primary key.

• In a patient database, a patient number could be used as a key field


to uniquely identify each patient record in the doctors’ patient file.
the patient name could not be a key since there may be more than one
patient with the same name.
Candidate key
• Candidate keys are defined as set of field from which primary key can be selected.
• A candidate key is a set of one or more fields/columns that can identify a record uniquely in a table.
• There can be multiple candidate keys in one table. Each candidate key can work as a primary key.
• Example, in a table below (ID, Roll No. and Email are candidate keys, because both can uniquely identify the
employee record in the table)
Primary key
• Primary key is a candidate key that is most appropriate to become main key of the table.
• Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database table.
• It can not accept null or duplicate values.
• Only one candidate key can be primary key.
• Primary keys is represented by an oval shape
with the text underlined
Example:
Alternate key
• An alternate key is a key that can work as a primary key. Basically, it is a candidate key that currently is not a
primary key.
• Example, in a table below, Roll No. and Emails become alternate keys when we define ID as a primary key.
Foreign key
• Foreign key is a field in a database table that is primary key in another table.
• A foreign key is a column which is added to one table to create a relationship with another table.
•We represent foreign keys with an asterisk e.g.
Differences between primary key and foreign key
Primary key Foreign key

Primary key uniquely identifies a record in the Foreign key is a field in the table, that is a primary
table key in another table

Primary key can not accept null values Foreign key can accept multiple null values

We can have only one primary key in a table We can have more than one foreign key in a table
Non-key attributes
• Non-key attributes are attributes other than candidate key attributes in a table.
Non-prime attributes
• Non-prime attributes are attributes other than primary attributes
Attributes
• Attributes are properties of entities.
- For example, a student entity may have name, class, and age as attributes. Others include account-number and
balance for account entity in a bank, customer-id, customer-name, customer-address for a customer entity, book
code, book title to describe a book entity.

• An attribute is represented as an oval in an ER diagram.


Every (oval) represents one attribute and
is directly connected to its entity (rectangle).
Value sets (domains) of attributes
• Each attribute in an entity set is associated with a value set or domain, which specifies the set of values that it may
hold.
• Domain: the set of permitted values for each attribute. For instances, attribute day may take any value from the set
{Monday, Tuesday,….Friday}.
• Value sets are typically specified using the basic data types such as integer, boolean, floating, enumeration, sub
range and so on.
• For example, a student's name cannot be a numeric value. It has to be alphabetic. A student's age cannot be
negative, etc.
• In some cases, entity may not have an applicable value for an attribute. For example: Fax number or apartment
number.
Null value
• For such attributes, an special attribute called null is created. Null means unknown.
Note: A null value is different from a zero value or a field that contains spaces.
Attribute types
1. Simple vs Composite
• Composite attributes can be further divided ( in a tree like structure) into smaller subparts, which represents
more basic attributes with independent meaning. Composite attributes are made of more than one simple
attribute. For example; date (day, month, year), a complete name may have first_name and last_name.
- Address is composed of other attributes such as pin code, state, country.
• Attributes that are not divisible are called simple or atomic attributes.
For example, a student's phone number, employee number, customer id, etc
2. Single-valued Vs Multi-valued
• Attributes that hold single value are called single-valued attributes. E.g. Registration number, Age, place of birth,
etc
• Multi-valued attributes hold more than one value. For example, a person can have more than one phone number,
email address, vehicle, etc.
• Another example is a teacher entity having multiple subject values.
• Multi-valued attribute are depicted by double ovals in ER diagrams.
3. Stored Vs Derived
• Derived attributes are the attributes whose value is dynamic and derived from another attribute present in the
database. For example, person age is dynamic as it changes over time and can be derived from the birthdate.

• The attributes which need to be stored permanently is a


stored attribute e.g. name of a student.
- Age can be derived from the birthdate,.
-For a circle, the area can be derived from the radius.
-Derived attributes are depicted by dashed ellipse/oval in ERD.
Relationships
• The association between two or more entities is called a relationship. Relationships are represented by diamond
shapes and are labeled using verbs.
• There are two types: strong relationship (single diamond) and weak relationship (double diamond).
• For example, an employee works in a department, a student enrolls in a course.
• Here, Works in and Enrolls are called relationships.
• For example, the entity “carpenter” may be related to the entity “table” by the relationship “builds” or “makes”.
Degree of relationships
• Refers to the number of entity sets that participate in a relationship set.
• Three cases:
- Unary (degree 1): between two instances of one entity type

e.g. Student manages student, An employee reports_to employee,


a particular subject is a prerequisite for another subject.
- Binary = degree 2 (between the instances of two entity types)

e.g. An employee works-for department.. Teacher teaches Student,


student enroll in a course. Generally, most relationship sets in a
database system are binary.
- Ternary = degree 3 ( among the instances of three entity types)

e.g. customer purchase item from a shop keeper


• Relationships between more than two entity sets are rare
-Suppose employees of a bank may have jobs (responsibilities) at multiple branches, with different jobs at different
branches. Then there is a ternary relationship set between entity sets employee, job, and branch.
- The University might need to record which teachers taught which subjects
in which courses.
- Department employs Employee and Recruiters.
- Employee works on the department at a particular location
Mapping cardinalities
• Mapping cardinalities define the number of instances of one entity set, which can be associated with the number of
instances of other set via relationship set.
• One-to-one – when only one instance of an entity from entity set A is associated with at most one entity of entity
set B and vice versa.
• For example, a relationship between a college and a principal. Each student has
only one student ID, and each student ID is assigned to only one person.
-For each employee there exists a unique office and for each office there exists
a unique employee.
Or employee assigned a parking space.
One-to-many
• One entity from entity set A can be associated with more than one entities of entity set B however an entity from
entity set B, can be associated with at most one entity.
• When more than one instance of entity is associated with the relationship , it is marked as N or M. The image
below reflects that only one instance of entity on the left and more than one instance of entity on the right can be
associated with the relationship. It depicts one-to-many relationship.
• For example, scientist can invent many inventions, but the invention is done by the
only specific scientist. A department has many employees, each employee is
assigned to one department
Many-to-one
• When more than one instance of the entity on the left, and only one instance of an entity on the right associates
with the relationship then it is known as a many-to-one relationship.
• More than one entities from entity set A can be associated with at most one entity of entity set B, however an entity
from entity set B can be associated with more than one entity from entity set A.
• For example; student enrolls for only one course, but a course can have many students.
Students can study in a single college but a student cannot study in many colleges
at the same time.
• Employee and department relationship
Many-to-many
• When more than one instance of the entity on the left, and more than one instance of an entity on the right
associate with the relationship, then it is known as a many-to-many relationship.
• For example, employee can be assigned to many projects and
project can have many employees.
A student takes many courses, and many students take a course

You might also like