You are on page 1of 74

Week 03

Data base Design(Cont.)


Database System
COSC-2103

Database Systems (Fall 2021) - Zahid.aslam@iub


SDLC - Where are we?
1. Systems planning phase Data design
2. Systems analysis phase
3. Systems design phase
4. Systems implementation phase
5. Systems operation, support, and security phase

Database Systems (Fall 2021) - Zahid.aslam@iub


Overview of Database Design
What are the entities and relationships in the
enterprise?
What information about these entities and
relationships should we store in the database?
What are the integrity constraints or business
rules that hold?
A database `schema’ in the ER Model can be
represented pictorially (ER diagrams).
Can map an ER diagram into a relational
schema.

Database Systems (Fall 2021) - Zahid.aslam@iub


Data modeling versus Data design
 Data modeling - DFD diagrams
What data is needed
 Data design
How will the data be stored and retrieved

Database Systems (Fall 2021) - Zahid.aslam@iub


Database Design

 Three phases of database design:

Conceptual database design


Logical database design
Physical database design.

Database Systems (Fall 2021) - Zahid.aslam@iub


Conceptual Database Design

 Process of constructing a model of the data


used in an enterprise, independent of all
physical considerations.

 Data model is built using the information in


users’ requirements specification.

 Conceptual data model is source of


information for logical design phase.

Database Systems (Fall 2021) - Zahid.aslam@iub


Logical Database Design

 Process of constructing a model of the


data used in an enterprise based on a
specific data model (e.g. relational), but
independent of a particular DBMS and
other physical considerations.

 Conceptual data model is refined and


mapped on to a logical data model.

Database Systems (Fall 2021) - Zahid.aslam@iub


Physical Database Design
 Process of producing a description of the
database implementation on secondary storage.

 Describes base relations, file organizations, and


indexes used to achieve efficient access to data.
Also describes any associated integrity
constraints and security measures.

 Tailored to a specific DBMS system.

Database Systems (Fall 2021) - Zahid.aslam@iub


Overview of Database Design
 Conceptual design: (ER Model is used for this.)
 What are the entities and relationships we need?
 Logical design:
 Transform ER design to Relational Schema
 Schema Refinement: (Normalization)
 Check relational schema for redundancies and related
anomalies.
 Physical Database Design and Tuning:
 Consider typical workloads; (sometimes) modify the
 database design; select file types and indexes.

Database Systems (Fall 2021) - Zahid.aslam@iub


Storage choices
 File based
Text-based - XML
Binary
 Database systems
Relational
Object-based/oriented

Database Systems (Fall 2021) - Zahid.aslam@iub


ERM and ERD
Entity-Relationship Data Model (ERM)
is a detailed, logical representation of the
data for an organization or for a business
area.

Entity-Relationship Diagram (ERD)


is a graphical / diagramtic representation of
a Entity-Relationship Model.

Database Systems (Fall 2021) - Zahid.aslam@iub


Entity Relationship
Model

Database Systems (Fall 2021) - Zahid.aslam@iub


Entity Relationship Model

 Entity-Relationship model is a logical


representation of data in an organization.

 It describes the entire system as a collection


of entities (with their attributes) related to
one another (i.e. relationships).

Database Systems (Fall 2021) - Zahid.aslam@iub


Entity Relationship Model

 It is used to describe the elements of


a system and their relationships.

 It was introduced by Peter Chen in 1976.

Database Systems (Fall 2021) - Zahid.aslam@iub


Advantages of E-R Model
Some important advantages of E-R model
are as follows:

1.Conceptual Simplicity
2.Visual Representation
3.Effective Communication
4.Integrated with Relational Database
Model

Database Systems (Fall 2021) - Zahid.aslam@iub


Elements of E-R Model
Three major elements of an E-R model
are as follows:

1.Entities
2.Attributes
3.Relationships

Database Systems (Fall 2021) - Zahid.aslam@iub


Entities

Database Systems (Fall 2021) - Zahid.aslam@iub


Entity What is an Entity?
An entity has its own identity that
distinguishes it from other
entities.
– Examples:
 Person: PROFESSOR, STUDENT
 Place: STORE, UNIVERSITY, CITY
 Object: MACHINE, BUILDING
 Event: SALE, REGISTRATION
 Concept: ACCOUNT, COURSE,
EXAM
Database Systems (Fall 2021) - Zahid.aslam@iub
Entity Naming Guidelines
Entity Name should be;
–A Singular Noun and in Capital
letters.

–Descriptive and specific to the


organization.

–Concise.

Database Systems (Fall 2021) - Zahid.aslam@iub


EntityEntity Type or just Entity
Entity type is a term that is used for an
entity, it means that what type of
entity you are defining.

Thus entity type means simply an


Entity. e.g.
STUDENT, CLASS, TEACHER,
CUSTOMER

Database Systems (Fall 2021) - Zahid.aslam@iub


Entity
Entity Instance
is a member of entity
class or the single
occurrence or value of an entity type.
e.g. All the individual
students entered in a student
table. STUDENT

Ali, Mueed, Faiza, Uzair, Sajid, Khizra, Nabeel …..


Database Systems (Fall 2021) - Zahid.aslam@iub
Entity Entity Set
The collection/set all entity
instances/values of a particular entity
type/entity is called entity set,

Example:
All ofthe students in a university of entity type
STUDENT.

Database Systems (Fall 2021) - Zahid.aslam@iub


Attributes

Database Systems (Fall 2021) - Zahid.aslam@iub


Attributes
Characteristics of an entity are called its
attributes

STUDENT
Student_ID, Student_Address,
Student_Phone, Student_Class,
…. etc.

Database Systems (Fall 2021) - Zahid.aslam@iub


Attributes
Naming Guidelines
An attribute name;
–Should be a noun and capitalize
the first letter of each word.
(Example: Student_ID.)

–Should be unique.

–Should follow a standard format.


Example: Student_GPA, not
Database Systems (Fall 2021) - Zahid.aslam@iub
Attributes
Naming Guidelines
Similar attributes of different
entity types should use similar
conventions but unique names.

Example:
Faculty_Residence_City_Name
Student_Residence_City_Name

Database Systems (Fall 2021) - Zahid.aslam@iub


Attributes
Defining Guidelines
An attribute definition should;
–State what the attribute is ? and why it is
important ?
–Make clear what is and isn’t included in the
attribute's value.
–Define any aliases (same attribute with
different names)
–Indicate if this attribute is really required
or not.
–Indicate any relationships with other
attributes.

Database Systems (Fall 2021) - Zahid.aslam@iub


Attributes

 Attribute Domain
 The set of all possible
values / instances that an
attribute can take,
 e.g. entity PAKISTAN-CITY
can take any valid city of
Pakistan as a value.

Database Systems (Fall 2021) - Zahid.aslam@iub


Relationships

Database Systems (Fall 2021) - Zahid.aslam@iub


Relationships
A relationship, in the context of a databases, is
a natural situation / logical connection that
exists between two entities.

The entities that participate in a relationship


are called participants.

A relationships may be between different


entities as well as to the entity itself.

Database Systems (Fall 2021) - Zahid.aslam@iub


Relationships
A relationship, is established on the basis of
real or natural logical connection between the
participant entities.
e.g.
STUDENT and TEACHER
STUDENT and STUDENT
SUPPLIER and SHIPPER

Database Systems (Fall 2021) - Zahid.aslam@iub


Relationships
A relationship may be Total (if all of the entities
in the entity set participate in the relationship)

or

A relationship may be Partial (if some subset


of the entity set participate into the
relationship).

Database Systems (Fall 2021) - Zahid.aslam@iub


Entity Relationship
Diagram

Database Systems (Fall 2021) - Zahid.aslam@iub


E-R Diagram
E-R Diagram is a graphical representation of
E-R model using a set of standard symbols.

ER-diagram represents the previous three


elements of ER-Model in more detail using
different types of symbols / diagrams.

Each symbol/diagram is actually a description


of an element, conveying or adding some
particular meanings

Database Systems (Fall 2021) - Zahid.aslam@iub


Entities
ERD Symbols Representing
Different Types of Entities

Database Systems (Fall 2021) - Zahid.aslam@iub


ERD Symbol of An
Entity
Entities should always be placed in a plane
rectangle.

STUDENT CLASS PROFESSOR

Database Systems (Fall 2021) - Zahid.aslam@iub


Types of Entities
Different types of entities are represented in
E-R diagram as follows;

1.Strong Entities
2.Weak Entities
3.Associative Entities

Database Systems (Fall 2021) - Zahid.aslam@iub


ERD Symbols For Types of
Entity
Strong Entity
The Strong Entity is the one
whose existence does not
depend on the existence of
any other entity in a schema.

A strong entity always has the


primary key in its set of
attributes.

Database Systems (Fall 2021) - Zahid.aslam@iub


ERD Symbols For Types of
Entity
Strong Entity
It is denoted by a single
rectangle, the same symbole is
used for the entity itself.

Database Systems (Fall 2021) - Zahid.aslam@iub


ERD Symbols For Types of
Entity Weak Entity
The existence of a weak entity
depends on the existence of
an other entity in the entity set
of a database schema.
A weak entity does not have a
primary key rather it mus have
a foreign key.
The foreign key will be the
primary key of some other
(strong and related) entity.
Database Systems (Fall 2021) - Zahid.aslam@iub
ERD Symbols For Types of
Entity Weak Entity
In a relational database, a
weak entity cannot be
uniquely identified by its
attributes alone; therefore, it
uses a foreign key in
conjunction to some primary
key of another related entity

Database Systems (Fall 2021) - Zahid.aslam@iub


ERD Symbols For Types of
Entity Associative Entity
This is an additional entity which
come into existence where many-
to-many relationships are build.
It is denoted by a cross rectangle
within another rectangle

Database Systems (Fall 2021) - Zahid.aslam@iub


ERD Symbols For Types of
Entity Associative Entity
Relational database requires the
implementation of a separate
base relation (or base table) to
resolve many-to-many
relationships.
This base relation represents this
entity and is called, informally, an
associative table.

Database Systems (Fall 2021) - Zahid.aslam@iub


Attribute
s
ERD Symbols Representing
Different Types of
Attributes

Database Systems (Fall 2021) - Zahid.aslam@iub


Types of Attributes
Different types of Attributes are represented
in
RED as follows;

1.Simple Attribute
2.Composite Attribute
3.Single Valued Attribute
4.Multi-valued Attribute
5.Stored Attribute
6.Derived Attribute
7.Identifier Attribute

Database Systems (Fall 2021) - Zahid.aslam@iub


 1. Simple attribute
 You can’t divide a simple attribute any further. That’s it. You’ve got
the record and you can’t break it down any more than that. In our
example, the player’s email address is a simple attribute. We could
have split the email address into user and domain, but we don’t
need that level of granularity for a plain old email address.
Nickname is another simple attribute. We don’t want player names
to be publicly visible, so we’ll give them a single string of
alphanumeric characters for chat and messaging.

Database Systems (Fall 2021) - Zahid.aslam@iub


 2. Composite attribute
 You can use composite attributes to contain simple attributes. You
can always break a composite attribute down into two or more
simple attributes (or even more composite attributes, but we’ll get
into that later). For our database, the player’s name is being
recorded as first name and last name. Two simple attributes
combine to create a composite attribute.

Database Systems (Fall 2021) - Zahid.aslam@iub


 3. Derived attribute
 These are useful attributes that you can derive from other attributes.
We can use our player’s sign-up date to generate an attribute telling
us how long they’ve been playing the game. But there are more
derived attributes hidden in those basics. When designing our
database, we knew that we needed date of birth to make sure that
the player is only viewing age-appropriate content. But each
attribute can do double duty, and in this case, date of birth is also
handy for calculating the player’s age.

Database Systems (Fall 2021) - Zahid.aslam@iub


 4. Single-valued attribute
 You can only store one value for each
entity. Date of birth is a good example
for us. A player can only have a single
date of birth. Single-valued attributes
can be either simple or composite.

Database Systems (Fall 2021) - Zahid.aslam@iub


 5. Multi-valued attribute
 You can store more than one value for each entity. In our example,
we want to make sure that we can get in touch with our players no
matter what, so we’ll let them add more than one email address as
a backup. Multi-valued attributes can be either simple or composite.

Database Systems (Fall 2021) - Zahid.aslam@iub


Identifier Attribute
6.Identifiers are special attributes that are used for locating or providing context
to individual records.

Database Systems (Fall 2021) - Zahid.aslam@iub


 7. Stored Attribute :
Stored attribute is an attribute which are physically stored in the
database.
Assume a table called as student. There are attributes such as
student_id, name, roll_no, course_Id. We cannot derive value of
these attribute using other attributes. So, these attributes are called
as stored attribute.

Database Systems (Fall 2021) - Zahid.aslam@iub


Relationships

Database Systems (Fall 2021) - Zahid.aslam@iub


Degree of Relationships
A relationship may consist of many entities. The
number of entities in a relationship is called
degree of relationship. The types of
relationships with respect to degree are as
follows:
•Unary Relationship: only one entity is involved
•Binary Relationship: Two entities are
involved
•Ternary Relationship: Three entities are
involved

Database Systems (Fall 2021) - Zahid.aslam@iub


Unary Relationship

• Relationship between the instances of one


entity type.

Is_married_to Manages

EMPLOYEE
PERSON

Database Systems (Fall 2021) - Zahid.aslam@iub


Binary Relationship
Binary Relationships:
one-to-one
one-to-many
many-to-one
many-to-many

Database Systems (Fall 2021) - Zahid.aslam@iub


Binary Relationship
Relationship between the instances of two entity
type.

Is_assigne Contains
d PARKING
EMPLOYEE Project
SPACE Employee

One-to-One One-to-Many
Can also have many to
many!

Database Systems (Fall 2021) - Zahid.aslam@iub


Ternary Relationship
A simultaneous relationship among instances of
three entity types.

PART

Supplies

VENDOR WAREHOUSE

Database Systems (Fall 2021) - Zahid.aslam@iub


Binary Relationship
 One-to-one − When only one instance of an entity is associated
with the relationship, it is marked as '1:1'. The following image
reflects that only one instance of each entity should be
associated with the relationship. It depicts one-to-one
relationship.
 One-to-many − When more than one instance of an entity is
associated with a relationship, it is marked as '1:N'. The following
image reflects that only one instance of entity on the left and
more than one instance of an entity on the right can be
associated with the relationship. It depicts one-to-many
relationship.
 Many-to-one − When more than one instance of entity is
associated with the relationship, it is marked as 'N:1'. The
following image reflects that more than one instance of an entity
on the left and only one instance of an entity on the right can be
associated with the relationship. It depicts many-to-one
relationship.
 Many-to-many − The following image reflects that more than one
instance of an entity on the left and more than one instance of an
entity on the right can be associated with the relationship. It
depicts many-to-many relationship.
Database Systems (Fall 2021) - Zahid.aslam@iub
Database Systems (Fall 2021) - Zahid.aslam@iub
Relationship Cardinalities

Database Systems (Fall 2021) - Zahid.aslam@iub


Relationship Cardinalities
One-to-many (Optional):
STUDENT----BOOK (in library) both are optional for
each other
One-to-many (Mandatory): PROJECT----EMPLOYEE

project must has some members but for employee


it is optional

Database Systems (Fall 2021) - Zahid.aslam@iub


Relationship Cardinalities

STUDENT BOOK

PROJECT EMPLOYEE

Database Systems (Fall 2021) - Zahid.aslam@iub


University
ERD

Database Systems (Fall 2021) - Zahid.aslam@iub


Database Systems (Fall 2021) - Zahid.aslam@iub
3.4 – Degree of Relationships
3.5 – Subtype & Supertype

Database Systems (Fall 2021) - Zahid.aslam@iub


Relationships

Database Systems (Fall 2021) - Zahid.aslam@iub


Degree of Relationships
A relationship may consist of many entities. The
number of entities in a relationship is called
degree of relationship. The types of
relationships with respect to degree are as
follows:
•Unary Relationship: only one entity is involved
•Binary Relationship: Two entities are
involved
•Ternary Relationship: Three entities are
involved

Database Systems (Fall 2021) - Zahid.aslam@iub


Unary Relationship

• Relationship between the instances of one


entity type.

Is_married_to Manages

EMPLOYEE
PERSON

Database Systems (Fall 2021) - Zahid.aslam@iub


Binary Relationship
Binary Relationships:
one-to-many
many-to-one
many-to-many

Database Systems (Fall 2021) - Zahid.aslam@iub


Binary Relationship
Relationship between the instances of two entity
type.

Is_assigne Contains
d PARKING
EMPLOYEE PRODUCT
SPACE PRODUCTS
LINE

One-to-One One-to-Many
Can also have many to
many!

Database Systems (Fall 2021) - Zahid.aslam@iub


Ternary Relationship
A simultaneous relationship among instances of
three entity types.

PART

Supplies

VENDOR WAREHOUSE

Database Systems (Fall 2021) - Zahid.aslam@iub


Relationship Cardinalities

Database Systems (Fall 2021) - Zahid.aslam@iub


Relationship Cardinalities
One-to-one relationship
Each entity in the relationship will have exactly one related
entity
One-to-many (Optional):
STUDENT----BOOK (in library) both are optional for
each other
One-to-many (Mandatory): PROJECT----EMPLOYEE

project must has some members but for employee


it is optional

Database Systems (Fall 2021) - Zahid.aslam@iub

You might also like