0% found this document useful (0 votes)
13 views

DB - Chapter 3

Uploaded by

Muhammad Shahbaz
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

DB - Chapter 3

Uploaded by

Muhammad Shahbaz
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 51

Database Design Using the E-R

Model
E-R Model

● A logical representation of the data for an organization or for a business


area, using entities for categories of data and relationships for associations
between entities.
● An E-R model is normally expressed as an entity-relationship diagram.
Entity

● An entity is a thing in a real-world with independent existence.


● An entity is a person, a place, an object, an event, or a concept in the user
environment about which the organization wishes to maintain data.
● An entity can be of two types :
○ Tangible Entity: Person, Place, Object
○ Intangible Entity: Event, Concept
Entity

Person: EMPLOYEE, STUDENT, PATIENT


Place: STORE, WAREHOUSE, STATE
Object: MACHINE, BUILDING, AUTOMOBILE
Event: SALE, REGISTRATION, RENEWAL
Concept: ACCOUNT, COURSE, WORK CENTER
Entity

● A true data entity will have many possible instances, each with a
distinguishing characteristic.
● In the context of Namal University which of the following can be identified
as entity?
STUDENT, RECTOR, FACULTY, CHAIR, EXAM, SCHEDULE, ROOM,
NAMAL
Entity

● An entity is represented by a rectangle in ERD.


Strong Entity vs Weak Entity

Strong Entity: An entity that exists independently of other entity types.


Weak Entity: An entity whose existence depends on some other entity type.
Strong Entity vs Weak Entity
Naming Entity

● An entity name is a singular noun (CUSTOMER, STUDENT, or


AUTOMOBILE).
● An entity name should be specific to the organization. (CUSTOMER or
CLIENT).
● An entity type name should be concise, using as few words as possible.
(REGISTRATION or STUDENT REGISTRATION OF COURSE).
● An abbreviation, or a short name, should be specified for each entity name.
Defining Entity

● An entity type definition usually starts with “An X is ....”.


● Include a statement of what the unique characteristic is for each instance of
the entity type.
Example: An expense is a payment for the purchase of some good or service.
An expense is identified by a journal entry number.
Defining Entity

● Definition should make it clear what entity instances are included and not
included in the entity type; often, it is necessary to list the kinds of entities that
are excluded.
Example: A customer is a person or organization that has placed an order for
a product from us or one that we have contacted to advertise or promote our
products. A customer does not include persons or organizations that buy our
products only through our customers, distributors, or agents.
Defining Entity

● Definition can include a description of when an instance of the entity type is


created and deleted.
Example: A customer ceases to be a customer if it has not placed an order for
more than three years.
● Definition can include an example to specify what kind of data will be saved.
Defining Entity - Example
Attribute

● Each entity has a set of attributes associated with


it.
● An attribute is a property or characteristic of an
entity or relationship that is of interest to the
organization.
Attribute

STUDENT Student ID, Student Name, Home Address, Phone


Number, Major
AUTOMOBILE Vehicle ID, Color, Weight
EMPLOYEE Employee ID, Employee Name, Payroll Address, Skill
Required Versus Optional Attribute

Required: An attribute that must be present for each entity instance is called a
required attribute. E.g Name, Roll No etc.
Optional: An attribute that may not have a value is called an optional attribute. E.g
Phone No, Email etc.

A symbol might appear in front of each attribute to indicate whether it is required (*)
or optional (o), or required attributes will be in boldface, whereas optional attributes
will be in normal font.
Simple Versus Composite Attribute

Simple: An attribute that cannot be broken down into smaller components that are
meaningful to the organization. E.g: Vehicle ID, Color, Weight
Composite: An attribute that has meaningful component parts (attributes). The
components of composite attribute are written in round bracket separated by a
comma.
Single-Valued Versus Multi-Valued Attribute

Single-Valued: An attribute which accept only one value. E.g: DOB


Multi-Valued: An attribute that may take on more than one value for a given entity
instance. It can be indicated with curly brackets around the attribute name
Stored Versus Derived Attribute

Stored: An attribute that remain constant and fixed for an entity instance and must
be stored in relation.
Derived: An attribute whose values are based on other attributes and are not stored
directly in the database. It can be indicated with curly brackets around the attribute
name
Identifier Attribute

An attribute (or combination of attributes) whose value distinguishes instances of an


entity type.
Naming Attribute

● An attribute name is a singular noun or noun phrase.


● In naming attributes, we use an initial capital letter followed by lowercase
letters. If an attribute name consists of more than one word, we use a space
between the words
● An attribute name should be unique.
● Each attribute name should follow a standard format. (Student GPA vs GPA of
Student).
● Similar attributes of different entities should be prefixed by entity name or entity
abbreviation. (Student City, Faculty City)
Relationship

● A relationship is an association representing an interaction among the instances


of one or more entity types that is of interest to the organization.
● Relationships and their characteristics (degree and cardinality) represent
business rules
Relationship

● Consider the entities EMPLOYEE and COURSE, where COURSE represents


training courses that may be taken by employees.
● To track courses that have been completed by particular employees, we define a
relationship called completes between the two entity types
EMPLOYE
E completes
COURSE
Naming a Relationship

● Single verb phrase label


● Present tense and descriptive
● Some data modelers prefer the format with two relationship names, one to name
the relationship in each direction. For example:
EMPLOYE
E completes
COURSE
Where should the
attribute Date Completed
be placed on the E-R
diagram?

EMPLOYEE or
COURSE entity
Attributes on Relationships

● It is probably obvious to you that entities have attributes, but attributes may be
associated with a relationship (one-to-one, many to many) too.
● Hence Date Completed is a property of the relationship Completes, rather than a
property of either entity.
Associative Entity

● An associative entity is an entity type that associates the instances of one or


more entity types and contains attributes that are peculiar to the relationship
between those entity instances.
● An associative entity is represented by a rounded corner rectangle.
● Also known as bridge or intersection.
Associative Entity

● The identifier of associative entity can either be a combination of the identifier


that created the associative entity (i.e Employee Id and Course ID) or a surrogate
identifier (i.e Certificate Number).
Associative Entity

● How do you know whether to convert a relationship to an associative entity


type?
1. Many-to-Many Relationship
2. Ternary Relationship
3. Independent Meaning
4. One or more attributes in addition to the identifier.
DIY

Draw ERD of the following scenario:

A company wishes to store data about its product and order. They want to store
Product ID, Product Description, Product Price, Order ID, Order Date and Product
Quantity.
Degree of a Relationship

● The number of entity types that participate in a relationship.


Unary Relationship

● A relationship between instances of a single entity type.


● Also known as Recursive relationship.
Binary Relationship

● A relationship between the instances of two entity types.


Ternary Relationship

● A simultaneous relationship among the instances of three entity types.


Ternary Relationship
Ternary Relationship
Ternary Relationship
Cardinality Constraint

A rule that specifies the number of instances of one entity that can (or must) be
associated with each instance of another entity.

Minimum cardinality: The minimum number of instances of one entity that


may be associated with each instance of another entity.

Maximum cardinality: The maximum number of instances of one entity that


may be associated with each instance of another entity
Cardinality Constraint
Cardinality Constraint
Cardinality Constraint - Example

PATIENT Has Recorded PATIENT HISTORY: Each patient has one or more
patient histories. Each instance of PATIENT HISTORY “belongs to” exactly one
PATIENT.
Cardinality Constraint - Example

EMPLOYEE Is Assigned To PROJECT: Each PROJECT has at least one EMPLOYEE


assigned to it. (Some projects have more than one.) Each EMPLOYEE may or (optionally)
may not be assigned to any existing PROJECT (e.g., employee Pete) or may be assigned to
one or more PROJECTs.
Cardinality Constraint - Example

PERSON Is Married To PERSON: This is an optional zero or one cardinality


in both directions, because a person may or may not be married at a given point
in time.
Example

We have to make a system to keep the record of some songs. There


are multiple singers, each of whom have sung multiple songs. Some
of the songs are sung by multiple singers together. There are different
cassettes available in the market, which contain a mix of different
songs. A song can be repeated in multiple cassettes. All the cassettes
are produced by some production companies, while multiple
production companies cannot co-produce a cassette.
Example - Identify the Entities

We have to make a system to keep the record of some songs. There are multiple
singers, each of whom have sung multiple songs. Some of the songs are sung by
multiple singers together. There are different cassettes available in the market,
which contain a mix of different songs. A song can be repeated in multiple
cassettes. All the cassettes are produced by some production companies, while
multiple production companies cannot co-produce a cassette.

Entities: Song, Singer, Cassette, Production Company


Example - Identify the Relationship between Entities

● Singer sings a Song.


● Cassette contains Song.
● Cassette is produced by Production Company.
Example - Identify the Relationship between Entities
Example - Mapping the Cardinalities
Example - Adding the Associative Entity
DIY

You are required to create a conceptual data model of the data requirements for a
company that specializes in IT training. The Company has 30 instructors and can
handle up to 100 trainees per training session. The Company offers five advanced
technology courses, each of which is taught by a single teaching team. Each
instructor is a part of at-least one teaching teams or may be assigned to do a
research project which is assigned to only one instructor. Each trainee undertakes
one advanced technology course per training session.. There can be many
training sessions of a course throughout a year.

You might also like