Week 04

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 32

CS-2005 DATABASE

SYSTEMS
Week-4
WHAT IS GOOD DATABASE DESIGN?

 A good database design is, therefore, one that:

 Divides your information into subject-based tables to reduce redundant


data.
 Provides Access with the information it requires to join the information
in the tables together as needed.
 Helps support and ensure the accuracy and integrity of your information.
 Accommodates your data processing and reporting needs.
THE DESIGN PROCESS
1
• Determine the purpose of your database
• Find and organize the information
2 required
3
• Divide the information into tables

4
• Turn information items into columns

5
• Specify primary keys

6
• Set up the table relationships

7
• Refine your design

8
• Apply the normalization rules
IF YOU DON’T FOLLOW DESIGN/
MODEL THEN …
DESIGN PROCESS
CONCEPTUAL MODEL
 Model: an abstraction of a real-world object
or event
 Useful in understanding complexities of the
real-world environment
 Data model
 A diagram that displays a set of tables and the
relationships between them
WHAT IS AN ENTITY RELATIONSHIP
DIAGRAM (ERD)?
 ER model is used to show the Conceptual
schema of an organization.

 ER model can express the overall logical


structure of a database graphically.

 ERD is a data modeling technique used in


software engineering to produce a conceptual
data model of an information system.

 The model is later transformed into a Logical


model (e.g. relational) on which the physical
database is built
E-R Model

• It was proposed by Peter Chen in 1971 to create a uniform


convention which can be used for relational database.
• E-R Model stands for Entity-Relationship Model, also
known as E-R Diagram.
• E-R Model is a high-level conceptual data model diagram.
• E-R model helps us to systematically analyze data
requirements to produce a well-designed database.

8
E-R Model…

• The ER Model represents real-world entities and the


relationships between them.
• It is an easy to use graphical tool for modeling data.
• Widely used in Database Design.
• It is a GUI representation of the logical structure of a
database.

9
Why use ER Diagrams?

• Helps to describe entities, attributes, relationships.


• Provide a preview of how all your tables should connect, what fields are
going to be on each table.
• ER diagrams are translatable into relational tables which allows you to
build databases quickly.
• ER diagrams can be used by database designers as a blueprint for
implementing database.
• The database designer gains a better understanding about the
database with the help of ER diagram.

10
Advantages

• Simple: If we know the relationship between the attributes


and the entities we can easily build the ER Diagram for the
model.
• Effective Communication Tool: This model is used widely by
the database designers for communicating their ideas.
• Easy Conversion to any Model: This model can be converted
to any other model like relational, network, hierarchical
model etc.

11
Disadvantages

• No industry standard for notation: means one developer might use


notations which are not understood by other developers.

• Hidden information: As it is a high-level view so there are chances


that some details of information might be hidden.

12
SUMMARY OF ER-DIAGRAM NOTATION
Symbol Meaning

ENTITY TYPE

WEAK ENTITY TYPE

RELATIONSHIP TYPE

IDENTIFYING RELATIONSHIP TYPE

ATTRIBUTE

KEY ATTRIBUTE
MULTIVALUED ATTRIBUTE

COMPOSITE ATTRIBUTE

DERIVED ATTRIBUTE

E1 R E2 TOTAL PARTICIPATION OF E2 IN R

E1 N
R E2 CARDINALITY RATIO 1:N FOR E1:E2 IN R

(min,max)
R E STRUCTURAL CONSTRAINT (min, max) ON PARTICIPATION OF E IN R
14
Components of the ER Diagram

This model is based on three basic concepts:

• Entities.
• Attributes.
• Relationships.

Example

15
What is an Entity?

• An entity is a real-world thing which is distinguishable from


other.
• An entity can be place, person, object, event or a concept.
• Every entity is made up of some 'attributes' which represent that
entity.
• It is represented by a rectangle.
Examples:
• Person: Employee, Student, Patient.
• Place: Store, Building.
• Object: Machine, product, and Car.
• Event: Sale, Registration, Renewal.
• Concept: Account, Course.
16
GUIDELINES FOR NAMING AND DEFINING ENTITY
TYPES

 An entity type name is a singular noun


 An entity type should be descriptive and specific
 An entity name should be concise
 Event entity types should be named for the result of the
event, not the activity or process of the event.
Types of Entities

• Strong Entity
− Strong entity is an entity which has a key attribute.
− The primary key helps in identifying each entity uniquely.
− e.g., Faysal Bank is uniquely identified by its bank number.

• Weak Entity
− A weak entity cannot be uniquely identified by its own attributes.
− Weak entity types have partial keys.
− Partial Keys are set of attributes with the help of which the tuples of the weak entities
can be distinguished and identified.
− They are represented with double rectangles.

18
No Unique key

Partial Key/Discriminator 19
Partial Key

Weak Entity

Identifying
Relationship
What is an attribute?

• An attribute is a property or characteristic of the entity that holds it.


• For example, a student might have attributes: roll_no, name, address,
phone_no, etc.
• It is represented by an ellipse/oval.
• There exist a specific domain or set of values for each attribute from
where the attribute can take its values.
• For example, a student's name cannot be a numeric value. It has to be
alphabetic. A student's age cannot be negative, etc.

21
GUIDELINES FOR NAMING ATTRIBUTES

 An attribute name is a noun.


 An attribute name should be unique
 To make an attribute name unique and clear, each
attribute name should follow a standard format
 Similar attributes of different entity types should use
similar but distinguishing names.
Types of attributes

In ER diagram, attributes associated with an entity set


may be of the following types-

1. Simple attribute.
2. Composite attribute.
3. Single valued attribute.
4. Multi valued attribute.
5. Derived attribute.
6. Key attribute.

23
1. Simple attribute

― Simple attributes are atomic values, which cannot be divided


further.

Example:

CNIC

Here, student’s class, gender, dob are atomic values which can not be
divided further.
24
2. Composite attribute
― A composite attribute is made up of more than one
simple attribute.
― A composite attribute can be further divisible.
Example:

Here, the attributes “Name” and “Address” are composite attributes as they are composed of
many other simple attributes.

25
3. Single Valued Attribute:
― These are the attributes which can take only one
value at a time.
Example:

Here, all the attributes are single valued attributes as they can take
only one at a time.

26
4. Multi-Valued Attribute
―These are the attributes which can take more
than one value at a time.
― It is represented by a double ellipse.
Example:

Here, the attributes “Mob_no” and “Email_id” are multi-valued attributes as


they can take more than one value.
27
5. Derived Attribute
― These are the attributes which can be derived from
other attribute(s).
― It is represented by dashed ellipse.
Example:

Here, “age” is a derived attribute as it can be derived from the


attribute “dob”.
28
6. Key Attribute
―These are the attributes which can identify an entity
uniquely in an entity set.
― Key attributes should be underlined.
Example:

Here, the attribute “roll_no” is a key attribute as it can identify each student
uniquely.
29
7. Descriptive Attribute
―The descriptive attribute describes a relationship. It
gives additional information about the relationship.

Example:
Practice Question

Composite Attribute

Key Attribute
Relationship

Entity
Entity

Derived
Multi-valued Attributes Descriptive
Attribute
Attributes
s
CASE STUDY
A university registrar’s office maintains data about the following
entities:
1. courses, including number, title, credits, syllabus, and
prerequisites;
2. course offerings, including course number, year, semester, section
number, instructor(s), timings, and classroom;
3. students, including student-id, name, and program; and
4. instructors, including identification number, name, department, and
title. Further, the enrollment of students in courses and grades
awarded to students in each course they are enrolled for must be
appropriately modeled.

Construct an E-R diagram for the registrar’s office. Document all

You might also like