Lec 3 - IDB
Lec 3 - IDB
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
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 3
Balochistan University of Information Technology, Engineering & Management Sciences
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
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
One Many
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 15
Balochistan University of Information Technology, Engineering & Management Sciences
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 16
Balochistan University of Information Technology, Engineering & Management Sciences
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 17
Balochistan University of Information Technology, Engineering & Management Sciences
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
Department
Student
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 22
Balochistan University of Information Technology, Engineering & Management Sciences
Student
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 23
Balochistan University of Information Technology, Engineering & Management Sciences
Offers Department
Student
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 24
Balochistan University of Information Technology, Engineering & Management Sciences
Offers Department
Enrols In Student
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 25
Balochistan University of Information Technology, Engineering & Management Sciences
Offers Department
Takes
Enrols In Student
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 26
Balochistan University of Information Technology, Engineering & Management Sciences
Offers Department
Takes
Enrols In Student
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 27
Balochistan University of Information Technology, Engineering & Management Sciences
Takes
Enrols In Student
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 28
Balochistan University of Information Technology, Engineering & Management Sciences
Takes
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 29
Balochistan University of Information Technology, Engineering & Management Sciences
Takes
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 30
Balochistan University of Information Technology, Engineering & Management Sciences
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 31
Balochistan University of Information Technology, Engineering & Management Sciences
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
Description Product
Street address
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
Description Product
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 38
Balochistan University of Information Technology, Engineering & Management Sciences
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
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 40
Balochistan University of Information Technology, Engineering & Management Sciences
Description Product
Has A
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 41
Balochistan University of Information Technology, Engineering & Management Sciences
Introduction to Database Systems Spring 2015 Mohammad Imran April 14, 2015 42
Balochistan University of Information Technology, Engineering & Management Sciences
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