0% found this document useful (0 votes)
50 views44 pages

Lec 3 - IDB

This document is a lecture on logical database modeling using entity relationship diagrams (ERDs). It discusses key concepts for ERDs including entities, attributes, relationships, and cardinality. Entities represent objects of interest, attributes are facts about entities, and relationships link entities. The lecture provides examples and guidelines for constructing ERDs to model real-world scenarios like a university database.

Uploaded by

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

Lec 3 - IDB

This document is a lecture on logical database modeling using entity relationship diagrams (ERDs). It discusses key concepts for ERDs including entities, attributes, relationships, and cardinality. Entities represent objects of interest, attributes are facts about entities, and relationships link entities. The lecture provides examples and guidelines for constructing ERDs to model real-world scenarios like a university database.

Uploaded by

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

Balochistan University of Information Technology, Engineering & Management Sciences

Introduction to
Database Systems
Mohammad Imran
Lecturer
Department of Information Technology
Balochistan University of Information Technology, Engineering & Management Science

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 1
Balochistan University of Information Technology, Engineering & Management Sciences

Lecture 2
Logical Database Modeling
Entity Relationship Diagram

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 2
Balochistan University of Information Technology, Engineering & Management Sciences

Entity Relationship Modelling


• Consists of : • Example
o Entities - objects or items o In a University database we
might have entities for
of interest Students, Courses and
o Attributes - facts about, Lecturers
or properties of, an entity o Students might have
o Relationships - links attributes such as their ID,
Name, and Program, and
between entities could have relationships
with Courses (enrolment)
and Lecturers (tutor/tutee)

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 3
Balochistan University of Information Technology, Engineering & Management Sciences

Entity Relationship Diagrams


• E/R Models are often
Lecturer ID
represented as E/R
Name Program
diagrams that
o Give a conceptual view Teaches Student
of the database
o Are independent of the
choice of DBMS Course Studies
o Can identify some
problems in a design

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 4
Balochistan University of Information Technology, Engineering & Management Sciences

Entities
• Entities represent objects or things of interest
o Physical things like students, lecturers, employees,
products
o More abstract things like courses, orders, programs,
projects

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 5
Balochistan University of Information Technology, Engineering & Management Sciences

Entities
• Entities have
o A general type or class, such as Lecturer or Course
o Instances of that particular type, such as Imran, Babar are
instances of Lecturer
o Attributes (such as name, email address)

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 6
Balochistan University of Information Technology, Engineering & Management Sciences

Diagramming Entities
• In an E/R Diagram, an
Lecturer ID
entity is usually drawn as
a box with rounded or Name Program

may be unrounded
corners Teaches Student

• The box is labelled with


the name of the class of
objects represented by Course Studies

that entity

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 7
Balochistan University of Information Technology, Engineering & Management Sciences

Attributes
• Attributes are facts, properties, or details about an entity
o Students have IDs, names, programs, addresses, …
o Courses have codes, titles, credit hours …

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 8
Balochistan University of Information Technology, Engineering & Management Sciences

Attributes
• Attributes have
o A name
o An associated entity

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 9
Balochistan University of Information Technology, Engineering & Management Sciences

Diagramming Attributes
• In an E/R Diagram
Lecturer ID
attributes may be drawn
Name Program
as ovals
• Each attribute is linked Teaches Student
to its entity by a line
• The name of the
attribute is written in the Course Studies

oval

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 10
Balochistan University of Information Technology, Engineering & Management Sciences

Relationships
• Relationships are an association between two or more
entities
o Each Student takes several Courses
o Each Course is taught by a Lecturer
o Each Employee works for a single Department

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 11
Balochistan University of Information Technology, Engineering & Management Sciences

Relationships
• Relationships have
o A name
o A set of entities that participate in them
o A degree - the number of entities that participate (most
have degree 2)

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 12
Balochistan University of Information Technology, Engineering & Management Sciences

Cardinality Ratios
• Each entity in a relationship can participate in zero, one,
or more than one instances of that relationship
• This leads to 3 types of relationships

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 13
Balochistan University of Information Technology, Engineering & Management Sciences

Cardinality Ratios
• One to one (1:1)
o Each lecturer has a unique office
• One to many (1:M)
o A lecturer may teach many students, but each student has just one
teacher
• Many to many (M:M)
o Each student takes several Courses, and each Course is taken by
several students

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 14
Balochistan University of Information Technology, Engineering & Management Sciences

Diagramming Relationships
• Relationships are links
Lecturer ID
between two entities
Name Program
• The name is given in a
diamond box Teaches Student

• The ends of the link show


cardinality
Course Studies

One Many

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 15
Balochistan University of Information Technology, Engineering & Management Sciences

Removing M:M Relationships


• Many to many
relationships are difficult Student
to represent Student
Has
• We can split a many to
many relationship into
Studies Enrolment
two one to many
relationships In
• An entity represents the Course

M:M relationship Course

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 16
Balochistan University of Information Technology, Engineering & Management Sciences

Making E/R Models


• To make an E/R model you need to identify
o Entities
o Attributes
o Relationships
o Cardinality ratios
• from a description

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 17
Balochistan University of Information Technology, Engineering & Management Sciences

Making E/R Models


• General guidelines
o Since entities are things or objects they are often
nouns in the description
o Attributes are facts or properties, and so are often
nouns also
o Verbs often describe relationships between entities

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 18
Balochistan University of Information Technology, Engineering & Management Sciences

Example
• A University consists of a number of Departments
• Each department offers several Programs
• A number of Courses make up each Program
• Students enrol in a particular Program and take Courses
towards the completion of that Program.
• Each Course is taught by a Lecturer from the appropriate
department, &
• Each lecturer teaches a group of students
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 19
Balochistan University of Information Technology, Engineering & Management Sciences

Example – Entities Identified


• A University consists of a number of Departments
• Each department offers several Programs
• A number of Courses make up each Program
• Students enrol in a particular Program and take Courses
towards the completion of that Program
• Each Course is taught by a Lecturer from the
appropriate department &
• Each lecturer teaches a group of students
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 20
Balochistan University of Information Technology, Engineering & Management Sciences

Example – Relationships Identified


• A University consists of a number of Departments
• Each department offers several Programs
• A number of Courses make up each Program
• Students enrol in a particular Program and take Courses
towards the completion of that Program
• Each Course is taught by a lecturer from the
appropriate department, and each lecturer teaches a
group of students
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 21
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram


Entities: Department, Program, Course, Lecturer, Student

Department

Program Course Lecturer

Student

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 22
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram


Each department offers several Programs
Offers Department

Program Course Lecturer

Student

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 23
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram


A number of Courses make up each Programs

Offers Department

Program Includes Course Lecturer

Student

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 24
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram


Students enrol in a particular Program

Offers Department

Program Includes Course Lecturer

Enrols In Student

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 25
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram


Students … take Courses

Offers Department

Program Includes Course Lecturer

Takes

Enrols In Student

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 26
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram


Each Course is taught by a lecturer

Offers Department

Program Includes Course Teaches Lecturer

Takes

Enrols In Student

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 27
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram


a lecturer from the appropriate department

Offers Department Employs

Program Includes Course Teaches Lecturer

Takes

Enrols In Student

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 28
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram


each lecturer teaches a group of students

Offers Department Employs

Program Includes Course Teaches Lecturer

Takes

Enrols In Student Teaches

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 29
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram

Offers Department Employs

Program Includes Course Teaches Lecturer

Takes

Enrols In Student Tutors

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 30
Balochistan University of Information Technology, Engineering & Management Sciences

Entities and Attributes


• Sometimes it is hard to tell if something should be
an entity or an attribute
o They both represent objects or facts about the world
o They are both often represented by nouns in descriptions

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 31
Balochistan University of Information Technology, Engineering & Management Sciences

Identifying Entities and Attributes


• General guidelines
o Entities can have attributes but attributes have no smaller
parts
o Entities can have relationships between them, but an
attribute belongs to a single entity

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 32
Balochistan University of Information Technology, Engineering & Management Sciences

Identification - Example
• We want to represent information about products in a
database
• Each product has a description, a price and a supplier
• Suppliers have addresses, phone numbers, and names
• Each address is made up of a street address, a city, and a
postcode

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 33
Balochistan University of Information Technology, Engineering & Management Sciences

Identify - Entities/Attributes
• Entities or attributes:
• product
• description
• price
• supplier
• address
• phone number
• name
• street address
• city
• postcode

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 34
Balochistan University of Information Technology, Engineering & Management Sciences

Identified - Entities/Attributes
• Entities or attributes: • Products, suppliers, and
• product addresses all have
• description
• price smaller parts so we can
• supplier make them entities
• address • The others have no
• phone number
• name
smaller parts and
• street address belong to a single entity,
• city so they are attributes
• postcode

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 35
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram w/o Relations


Price

Description Product

Street address

Name Supplier Address City

Phone number Postcode

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 36
Balochistan University of Information Technology, Engineering & Management Sciences

Example - Relationships
• Each product has a • Each supplier has an
supplier address
o Each product has a single o A supplier has a single
supplier but there is nothing to address
stop a supplier supplying o It does not seem sensible for
many products two different suppliers to have
o A many to one relationship the same address
o A one to one relationship

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 37
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram with Relations


Price

Description Product

Has A Street address

Name Supplier Has A Address City

Phone number Postcode

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 38
Balochistan University of Information Technology, Engineering & Management Sciences

Redundant One to One Relationships


• Some relationships • Example - the supplier-
between entities, A and address relationship
B, might be redundant if o Is one to one
o It is a 1:1 relationship between o Every supplier has an
A and B address
o Every A is related to a B and
every B is related to an A o We don’t need addresses
that are not related to a
supplier

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 39
Balochistan University of Information Technology, Engineering & Management Sciences

Redundant Relationships
• We can merge the two a x
entities that take part in
a redundant relationship b A B y

together c z

o They become a single


entity a x

o The new entity has all the


b AB y
attributes of the old one
c z

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 40
Balochistan University of Information Technology, Engineering & Management Sciences

Example - E/R Diagram


Price

Description Product

Has A

Name Supplier City

Phone number Postcode Street address

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 41
Balochistan University of Information Technology, Engineering & Management Sciences

Making E/R Diagrams - Cumulatively


1. From a description of 2. Draw the E/R diagram
the requirements and then
identify the a) Look at one to one
relationships as they
a) Entities might be redundant
b) Attributes b) Look at many to many
c) Relationships relationships as they
d) Cardinality ratios of the might need to be split
into two one to many
relationships
links

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 42
Balochistan University of Information Technology, Engineering & Management Sciences

Practice as much you can


• Identify the entities, attributes, relationships, and
cardinality ratios from the description

• Draw an entity-relationship diagram showing the items


you identified

Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 43
Balochistan University of Information Technology, Engineering & Management Sciences

Thank you

44
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015

You might also like