Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Course - DBMS: Course Instructor Dr.K. Subrahmanyam Department of CSE, KLEF

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 99

Course – DBMS

Course Instructor
Dr.K. SUBRAHMANYAM
Department of CSE, KLEF

1
Friday, August 28, 2020 CSE, KL UNIVERSITY
Announcement
1. First project presentation is scheduled on 28-1-2016, 2:00pm at PG
lab, 6th floor, PG Block. Each group should present their project
requirements and ER diagram during presentation. All students of the
class should be present during whole presentation. Students not
showing up for presentation without prior information will get negative
class attendance.
2. Yet 40% of the students have not registered their DBMS project topic
and group members. Last and final call for registration is on or before
21-1-2016. In case if the student does not register before 21-1-
2016, he or she should carry out the project individually and
randomly the topic will assigned by the faculty instructor.
3. Group members who have already registered their project topics should
discuss with faculty instructor on or before 23-1-2016 to identify
requirements of the topic. Because you should start preparing
requirements and ER- diagram for your project topic.
Note: It hinders your learning and creativity when others code/
design is copied. You should be ethical in preparing your own ER
diagrams, design plans and writing program code during your DBMS
Project design and development.

Friday, August 28, 2020 CSE, KL UNIVERSITY 2


Topics Covered in Todays Class

Unit 2: Data Modeling using the Entity-


Relationship(ER) diagram
- Entity Types, Entity Sets, Attributes and Keys

Friday, August 28, 2020 CSE, KL UNIVERSITY 3


Sample Database Application
 Example: HOD of CSE department calls you and asks to
develop the following application
“Develop a database application to automate the process of
course registration”
 Your first task should be to have a discussion with your
client i.e HOD, to identify the requirements of the
application.
 Requirements are as follows
 Department has students and faculty
 Department will offer a set of courses during each semester
 Each student in the department during course registration will be opting for
courses offered by the department
 Faculty will be handling courses

 Your second task should be to prepare a ER diagram


which shows the Design plan of the database application
to be developed.

Friday, August 28, 2020 CSE, KL UNIVERSITY 4


Example: House design plan

During plan preparation


Various notations and
Terminologies

Friday, August 28, 2020 CSE, KL UNIVERSITY 5


Design plan or ER diagram before actual development of the
application

Course
CourseNam
Code
USN e
Name

Opting
Student Courses

has
Handles
Offers

has
Faculty
Department

ID Name
Name

Friday, August 28, 2020 CSE, KL UNIVERSITY 6


Design plan or ER diagram before actual development of the
application

Attribute

Entity

Relationship

Requirements Were
- Department has students and faculty
- Department will offer a set of courses during each semester
- Each student in the department during course registration will be
opting for courses offered by the department
- Faculty will be handling courses
Friday, August 28, 2020 CSE, KL UNIVERSITY 7
Design plan or ER diagram before actual development of the
application

Constraints
- Each semester student
should register for minimum
of 20 credits and maximum
of 30 credits
- Each faculty can handle
a maximum two courses
During each semester

Requirements Were
- Department has students and faculty
- Department will offer a set of courses during each semester
- Each student in the department during course registration will be
opting for courses offered by the department
- Faculty will be handling courses
Friday, August 28, 2020 CSE, KL UNIVERSITY 8
What is Entity, Entity Types, Entity sets ?

 Entity is object in real world which


has independent existence.
 Example: Student, Course, Faculty, Car,
House, College, Book, Food
ER Diagram Notation for Entity: Rectangle
Student Courses

Friday, August 28, 2020 CSE, KL UNIVERSITY 9


Activity - Questionnaire

List out the Entities which you will come


across in real world.

Friday, August 28, 2020 CSE, KL UNIVERSITY 10


What is Entity Types, Entity sets ?

 Entity type is collection of entities with


common attributes
 Entity set collection of one or more attributes
Student Entity Type
USN Name Email ID Mobile No. DOB

1BM14CS001 Aditya aditya@bmsce.ac.in 9448444160 1-1-1997

1BM14CS002 Bharath bharath@bmsce.ac.in 8762244699 31-12-1996

Entity Set

Friday, August 28, 2020 CSE, KL UNIVERSITY 11


What is Attribute ?

 Attribute is a property that describes Entity.


Attributes:
USN, Name, Email ID,
Mobile Number, DOB
Student Entity Type
USN Name Email ID Mobile No. DOB

1BM14CS001 Aditya aditya@bmsce.ac.in 9448444160 1-1-1997

1BM14CS002 Bharath bharath@bmsce.ac.in 8762244699 31-12-1996

Entity Set What is Domain ?


Set of permitted values for an
Attribute.

Friday, August 28, 2020 CSE, KL UNIVERSITY 12


What is Attribute ?

 Attribute is a property that describes Entity.


Attributes:
USN, Name, Email ID,
Mobile Number, DOB
Student Entity Type
USN Name Email ID Mobile No. DOB

1BM14CS001 Aditya aditya@bmsce.ac.in 9448444160 1-1-1997

1BM14CS002 Bharath bharath@bmsce.ac.in 8762244699 31-12-1996

Entity Set ER Diagram Notation for Attribute: Ellipse


Email ID Mobile
USN Name No.

Student DOB

Friday, August 28, 2020 CSE, KL UNIVERSITY 13


Activity - Questionnaire

List attributes for


1.Car
2.Book

Friday, August 28, 2020 CSE, KL UNIVERSITY 14


Different categories of attributes
 Simple (Atomic) vs Composite
 Attributes that are not divisible are called Simple.
 Attributes that can be divided into smaller parts are called Composite.
 Ex.: Simple- USN, Composite- Name(First Name, Last Name),
Address(Street name, Area Name, Place)
 Single value vs Multiple valued
 Ex.: Single – USN, Multiple – Mobile numbers
 Stored vs Derived
 Ex.: Stored – DOB, Derived – Age
 Complex Attributes
 Ex.: {Address(Street name, Area Name, Place)}  Office address and
Residence Address
 Null values
 Ex. : Middle Name is Optional i.e. Gautham Sharma or Gautham K Sharma

Friday, August 28, 2020 CSE, KL UNIVERSITY 15


Attribute: ER diagram notations

Attribute

…..
Composite Attribute

Multivalued Attribute

Derived Attribute

Friday, August 28, 2020 CSE, KL UNIVERSITY 16


What is Key ?
 Key attribute is a attribute or a combination of
attributes which will uniquely identify
remaining attributes of entity.
 What are the Key attributes in the following
student table ?
USN Name Email ID Mobile No. DOB

1BM14CS001 Aditya aditya@bmsce.ac.in 9448444160 1-1-1997

1BM14CS002 Bharath bharath@bmsce.ac.in 8762244699 31-12-1996

Friday, August 28, 2020 CSE, KL UNIVERSITY 17


What is Key ?
 Key attribute is a attribute or a combination of
attributes which will uniquely identify
remaining attributes of entity.
 What are the Key attributes in the following
student table ?
USN Name Email ID Mobile No. DOB

1BM14CS001 Aditya aditya@bmsce.ac.in 9448444160 1-1-1997

1BM14CS002 Bharath bharath@bmsce.ac.in 8762244699 31-12-1996

USN
ER Diagram Notation for Entity: Rectangle

Friday, August 28, 2020 CSE, KL UNIVERSITY 18


What is Key ?
 Key attribute is a attribute or a combination of
attributes which will uniquely identify
remaining attributes of entity.
 What are the Key attributes in the following
student table ?

USN Name Email ID Mobile No. DOB

1BM14CS001 Aditya aditya@bmsce.ac.in 9448444160 1-1-1997

1BM14CS002 Bharath bharath@bmsce.ac.in 8762244699 31-12-1996

1BM14CS003 Dinesh K dineshk@bmsce.ac.in 8444160944 6-6-1998

1BM14CS004 Dinesh K Dineshk_4@bmsce.a 7446998762 6-6-1998


c.in

Friday, August 28, 2020 CSE, KL UNIVERSITY 19


What is Key ?
 Key attribute is a attribute or a combination of
attributes which will uniquely identify
remaining attributes of entity.
 What are the Key attributes in the following
student table ?
Faculty Departm Salary
ent
A CSE 20K

B CSE 21K

A EC 30K

B EC 27K

C CSE 22K

Friday, August 28, 2020 CSE, KL UNIVERSITY 20


What is Key ?
 Key attribute is a attribute or a combination of
attributes which will uniquely identify
remaining attributes of entity.
 What are the Key attributes in the following
student table ?
Faculty Departm Salary
ent
A CSE 20K

B CSE 21K

A EC 30K

B EC 27K

C CSE 22K

Friday, August 28, 2020 CSE, KL UNIVERSITY 21


What is Key ?
 Key attribute is a attribute or a combination of
attributes which will uniquely identify
remaining attributes of entity.
 What are the Key attributes in the following
student table ?
Faculty Departm Salary
ent What is the Salary of Employee
A CSE 20K whose name is A ?
B CSE 21K

A EC 30K

B EC 27K

C CSE 22K

Friday, August 28, 2020 CSE, KL UNIVERSITY 22


What is Key ?
 Key attribute is a attribute or a combination of
attributes which will uniquely identify
remaining attributes of entity.
 What are the Key attributes in the following
student table ?
Faculty Departm Salary
ent What is the Salary of Employee
A CSE 20K whose name is A ?
B CSE 21K

A EC 30K
Note:
B EC 27K Before determining the Key
C CSE 22K attribute, look at the values
present but it will
not be consistent
Friday, August 28, 2020 CSE, KL UNIVERSITY 23
Activity To DO
Attribute Represent Employee entity
using ER diagram notation
….. Which has following attributes
- Employee ID (Key)
Composite Attribute - Name
- Address(House No., Street
name, Area name, Place)
- Mobile Number (Can have
Multivalued Attribute
more than one )
- DOB
- Age
Derived Attribute

Entity

______ Key Attribute

Friday, August 28, 2020 CSE, KL UNIVERSITY 24


Topics Covered in Todays Class

Unit 2:
- Relationship Types, Relationship sets, Roles and
Structural Constraints
- Weak Entity Types

Friday, August 28, 2020 CSE, KL UNIVERSITY 25


Relationship Type
 A Relationship Type defines a relationship set among
entities of certain entity types.
 Example, an Faculty works_for a department, a student
enrolls_for in a course. Here, works_for and enrolls_for
are called relationships.
relationship
Works_for
Faculty Department

Enrolls_for
Student Course

Friday, August 28, 2020 CSE, KL UNIVERSITY 26


Relationship Type
 A Relationship Type defines a relationship set among entities of certain
entity types.
 Example, an Faculty works_for a department, a student enrolls_for in a
course. Here, works_for and enrolls_for are called relationships.

Dr. Guruprasad
CSE
Dr. Umadevi

Dr. Indiramma
ISE

Dr. Ashok

Faculty
Department
Entity Works_for
Entity
relationship
Friday, August 28, 2020 CSE, KL UNIVERSITY 27
Relationship Type
 A Relationship Type defines a relationship set among entities of certain
entity types.
 Example, an Faculty works_for a department, a student enrolls_for in a
course. Here, works_for and enrolls are called relationships.

Avinash
DBMS
Balaji

Chandan
Java

Dinesh

Student
Course
Entity enrolls_for
Entity
relationship
Friday, August 28, 2020 CSE, KL UNIVERSITY 28
Relationship Set
 An Relationship Set is a collection of relationships all belonging to one
relationship type.
Here relationship set,
has 4 relationships

Avinash
DBMS
Balaji

Chandan
Java

Dinesh

Student
Course
Entity enrolls_for
Entity
relationship
Friday, August 28, 2020 CSE, KL UNIVERSITY 29
Relationship
 The association among entities is called a
relationship. or A Relationship is one
instance in a Relationship Set.

Avinash
DBMS
Balaji

Chandan
Java

Dinesh

Student
Course
Entity enrolls_for
Entity
relationship
Friday, August 28, 2020 CSE, KL UNIVERSITY 30
Relationship Degree

 Binary Relationship: Degree two, two


entities are participating

Dr. Guruprasad
CSE
Dr. Umadevi

Dr. Indiramma
ISE

Dr. Ashok

Faculty
Department
Entity Works_for
Entity
relationship
Friday, August 28, 2020 CSE, KL UNIVERSITY 31
Relationship Degree
 Ternary Relationship: Degree three, three
entities are participating
Micro Systems
Pvt. Ltd

UNIQ systems Laptop


Pvt. Ltd Manufacturing
Supplier
Entity
Desktop
Hard disk Manufacturing

Keyboard
Project
Part supplies
Entity
Entity relationship
Friday, August 28, 2020 CSE, KL UNIVERSITY 32
Relationship Degree
 Ternary Relationship: Degree three, three
entities are participating
Micro Systems
Pvt. Ltd

UNIQ systems Laptop


Pvt. Ltd Manufacturing
Supplier
Entity
Desktop
Hard disk Manufacturing

Keyboard
Project
Part supplies
Entity
Entity relationship
Friday, August 28, 2020 CSE, KL UNIVERSITY 33
Recursive Relationship
 In some cases the same entity type participates in
more than once in a relationship type in different
roles.

Dr. Guruprasad Supervisor

Dr. Umadevi Subordinate

Dr. Indiramma Subordinate

Faculty
Entity supervision
relationship
Friday, August 28, 2020 CSE, KL UNIVERSITY 34
Recursive Relationship
 In some cases the same entity type participates in
more than once in a relationship type in different
roles.

Subordinate
Dr. Guruprasad
Supervisor

Dr. Umadevi

Dr. Indiramma

Supervisor
Principal

Faculty
Entity supervision
relationship
Friday, August 28, 2020 CSE, KL UNIVERSITY 35
Relationship Constraints or Structural Constraints

Two Types
1.Cardinality Ratios
a. One to one (1:1)
b. One to Many (1:M)
c. Many to Many (N:M)
2.Participation Constraints
a. Total
b. Partial

Friday, August 28, 2020 CSE, KL UNIVERSITY 36


Cardinality Ratios
 Cardinality is a constraint on a relationship specifying
the number of entity instances that a specific entity may
be related to via the relationship.
One to One:
One entity from entity set A can be associated with at most
one entity of entity set B and vice versa.

Friday, August 28, 2020 CSE, KL UNIVERSITY 37


Cardinality Ratios
 Cardinality is a constraint on a relationship specifying
the number of entity instances that a specific entity may
be related to via the relationship.
One to One:
One entity from entity set A can be associated with at most
one entity of entity set B and vice versa.

Dr. Guruprasad
CSE

Dr. Gowrishankar ISE

Faculty Department
Heads
Entity Entity
relationship
Friday, August 28, 2020 CSE, KL UNIVERSITY 38
Cardinality Ratios
 Cardinality is a constraint on a relationship specifying
the number of entity instances that a specific entity may
be related to via the relationship.
One to One:
One instance of one entity type can participate in one
instance of other entity type.

1 Heads 1
Faculty Department

Friday, August 28, 2020 CSE, KL UNIVERSITY 39


Cardinality Ratios
 Cardinality is a constraint on a relationship specifying the
number of entity instances that a specific entity may be related
to via the relationship.
One to Many:
One entity from entity set A can be associated with more than one
entities of entity set B however an entity from entity set B, can
be associated with at most one entity.

1 R M
Entity A Entity B

Friday, August 28, 2020 CSE, KL UNIVERSITY 40


Cardinality Ratios
 Cardinality is a constraint on a relationship specifying the
number of entity instances that a specific entity may be related
to via the relationship.
One to Many:
One entity from entity set A can be associated with more than one
entities of entity set B however an entity from entity set B, can
be associated with at most one entity.

Departme 1 Has M
Student
nt

Friday, August 28, 2020 CSE, KL UNIVERSITY 41


Cardinality Ratios
 Cardinality is a constraint on a relationship specifying the
number of entity instances that a specific entity may be related
to via the relationship.
Many to Many:
 One entity from A can be associated with more than one entity
from B and vice versa.

N R M
Entity A Entity B

Friday, August 28, 2020 CSE, KL UNIVERSITY 42


Cardinality Ratios
 Cardinality is a constraint on a relationship specifying the
number of entity instances that a specific entity may be related
to via the relationship.
Many to Many:
 One entity from A can be associated with more than one entity
from B and vice versa.

Friday, August 28, 2020 CSE, KL UNIVERSITY 43


Cardinality Ratios
 Cardinality is a constraint on a relationship specifying the
number of entity instances that a specific entity may be related
to via the relationship.
Many to Many:
 One entity from A can be associated with more than one entity
from B and vice versa.

Friday, August 28, 2020 CSE, KL UNIVERSITY 44


Participation Constraint
 Minimum number of relationship instance that each
entity can participate in.
 Total Participation − Each entity is involved in the
relationship. Total participation is represented by double
lines.
 Partial participation − Not all entities are involved in
the relationship. Partial participation is represented by
single lines.

Friday, August 28, 2020 CSE, KL UNIVERSITY 45


Participation Constraint
 Minimum number of relationship instance that each entity can
participate in.
 Total Participation − Each entity is involved in the
relationship. Total participation is represented by double lines.
 Partial participation − Not all entities are involved in the
relationship. Partial participation is represented by single lines.

Friday, August 28, 2020 CSE, KL UNIVERSITY 46


Participation Constraint
 Minimum number of relationship instance that each entity can
participate in.
 Total Participation − Each entity is involved in the
relationship. Total participation is represented by double lines.
 Partial participation − Not all entities are involved in the
relationship. Partial participation is represented by single lines.

What is wrong in following relationship representation ?

Friday, August 28, 2020 CSE, KL UNIVERSITY 47


Participation Constraint
 Minimum number of relationship instance that each entity can
participate in.
 Total Participation − Each entity is involved in the
relationship. Total participation is represented by double lines.
 Partial participation − Not all entities are involved in the
relationship. Partial participation is represented by single lines.

Friday, August 28, 2020 CSE, KL UNIVERSITY 48


Weak Entity
 A weak entity set is one which does not have any
primary key associated with it.
 A weak entity type normally has partial key which is the
set of attributes that can uniquely identify weak entities
that are related to same owner entity.

Partial Name
Key -----

Faculty
Dependents_of Dependent

Owner Weak
Entity Identifying Entity
Relationship

Friday, August 28, 2020 CSE, KL UNIVERSITY 49


Weak Entity
 A weak entity set is one which does not have any
primary key associated with it.
 A weak entity type normally has partial key which is the
set of attributes that can uniquely identify weak entities
that are related to same owner entity.

Dr. Guruprasad
Ram

Ravi
Dr. Gowrishankar

Ram
Owner
Entity Dependents_of Dependent (Children)
relationship Entity
Friday, August 28, 2020 CSE, KL UNIVERSITY 50
ER Diagram Symbols
Attribute

…..
Composite Attribute

Multivalued Attribute

Derived Attribute

Entity Weak Entity

______ Key Attribute ____ Partial Key

Friday, August 28, 2020 CSE, KL UNIVERSITY 51


ER Diagram Symbols

Relationship

Identifying Relationship

Total Participation of Entity A in R

Cardinality Ratio 1:N for Entity A : B in R

Friday, August 28, 2020 CSE, KL UNIVERSITY 52


Topics Covered in Todays Class

Unit 2:
ER diagram design for a given requirements

Friday, August 28, 2020 CSE, KL UNIVERSITY 53


Database Design
Database design: Why do we need it ?
 Agree on structure of the database before deciding on a
particular implementation

Consideration Issues such as:


 What entities to model
 How entities are related
 What constraints exist in the domain
 How to achieve good design

ER diagram is a conceptual design of database

Friday, August 28, 2020 CSE, KL UNIVERSITY 54


Database Design Process

Requirement Conceptual Logical, Physical,


Analysis Design Security etc.,

Requirement Analysis
- What is going to be stored ?
- How is it going to be used ?
- What are we going to do with the data ?
- Who should access the data ?

Technical and Non-technical


people are involved

Friday, August 28, 2020 CSE, KL UNIVERSITY 55


Database Design Process

Requirement Conceptual Logical, Physical,


Analysis Design Security etc.,

Conceptual Design
- A high-level description of the database.
- Sufficiently precise that technical people can understand it.
- But, not so precise that non-technical can not participate.

This is were Entity-Relationship (ER)


Diagram fits in.

Friday, August 28, 2020 CSE, KL UNIVERSITY 56


Database Design Process

Requirement Conceptual Logical, Physical,


Analysis Design Security etc.,

ER diagram is visual syntax for DB design which


is precise enough for technical points, but abstracted
enough for non-technical people.

Friday, August 28, 2020 CSE, KL UNIVERSITY 57


Main phases of Database Design

Friday, August 28, 2020 CSE, KL UNIVERSITY 58


ER Diagram Symbols
Attribute

…..
Composite Attribute

Multivalued Attribute

Derived Attribute

Entity Weak Entity

______ Key Attribute ____ Partial Key

Friday, August 28, 2020 CSE, KL UNIVERSITY 59


ER Diagram Symbols

Relationship

Identifying Relationship

Total Participation of Entity A in R

Cardinality Ratio 1:N for Entity A : B in R

Friday, August 28, 2020 CSE, KL UNIVERSITY 60


Activity: ER diagram
Decision: Relationship vs Empty

Question 1: What does the following ER diagram


say ?

Friday, August 28, 2020 CSE, KL UNIVERSITY 61


Activity: ER diagram
Decision: Relationship vs Empty

Question 2: What does the following ER diagram


say ?

Friday, August 28, 2020 CSE, KL UNIVERSITY 62


Activity: ER diagram
Decision: Relationship vs Empty
Question 3: What does the following ER diagram
say ?

Friday, August 28, 2020 CSE, KL UNIVERSITY 63


Activity: ER diagram design
Draw ER diagram for the following requirements
Universal Records has decided to store information about musicians who
perform on its albums (as well as other company data) in a database.
 Each musician that records at Universal has an ID(Key) and name.
 Each instrument used in songs recorded at Universal has a unique
identification number (Key) , a name and a musical key.
 Each album recorded on the Universal label has a unique identification
number (Key) , a title, a copyright date and a format.
 Each song recorded at Universal has a Song ID (Key), a title and an
author.
 Each musician may play several instruments, and a given instrument may
be played by several musicians.
 Each album has a number of songs on it, but no song may appear on
more than one album.
 Each song is performed by one or more musicians, and a musician may
perform a number of songs.
 Each album has exactly one musician who acts as its producer. A
musician may produce several albums, of course.

Friday, August 28, 2020 CSE, KL UNIVERSITY 64


Each musician that records at Universal has an ID (Key) and
name.

Friday, August 28, 2020 CSE, KL UNIVERSITY 65


Each instrument used in songs recorded at Universal has a unique
identification number (Key) , a name and a musical key.

Friday, August 28, 2020 CSE, KL UNIVERSITY 66


Each album recorded on the Universal label has a unique
identification number (Key) , a title, a copyright date and a format.

Friday, August 28, 2020 CSE, KL UNIVERSITY 67


Each song recorded at Universal has a Song ID
(Key), a title and an author.

Friday, August 28, 2020 CSE, KL UNIVERSITY 68


Each musician may play several instruments, and a given
instrument may be played by several musicians.

Friday, August 28, 2020 CSE, KL UNIVERSITY 69


Each album has a number of songs on it, but no song may
appear on more than one album.

Friday, August 28, 2020 CSE, KL UNIVERSITY 70


Each song is performed by one or more musicians, and a
musician may perform a number of songs.

M 1
M

N
N N

Friday, August 28, 2020 CSE, KL UNIVERSITY 71


Each album has exactly one musician who acts as its
producer. A musician may produce several albums, of
course

1 M

M M 1

N
N
M

Friday, August 28, 2020 CSE, KL UNIVERSITY 72


Topics Covered in Todays Class

Unit 2:
- Converting ER Diagrams to Tables
or Database design using ER-to-Relational Mapping

Friday, August 28, 2020 CSE, KL UNIVERSITY 73


 An ER diagram is a pictorial
representation of the information that
can be captured by a database. Such a
“picture” serves two purposes:
 It allows database professionals to describe an
overall design concisely yet accurately.
 (Most of) it can be easily transformed into the
relational schema.
 The ER diagram represents the conceptual level
of database design meanwhile the relational
schema (or database table) is the logical level
for the database design.

Friday, August 28, 2020 CSE, KL UNIVERSITY 74


Converting ER diagram to Tables
 Entities and Simple Attributes
 An entity type within ER diagram is turned into a
table.
 Each attribute turns into a column (attribute) in the
table. The key attribute of the entity is the primary
key of the table which is usually underlined.
USN DOB
Name

Student
Student Table
USN Name DOB
Primary
1BM14CS001 Aditya 1-1-1997
Key
1BM14CS002 Bharath 31-12-1996

Friday, August 28, 2020 CSE, KL UNIVERSITY 75


Converting ER diagram to Tables
 Multi-Valued Attributes
USN DOB
Name

Mobile
Student

Friday, August 28, 2020 CSE, KL UNIVERSITY 76


Converting ER diagram to Tables
 Multi-Valued Attributes
USN DOB
Name

Mobile
Student
Which of the following representation of the table for Multivalued
Attribute is best ?
USN Name DOB Mobile 1 Mobile 2
1BM14CS001 Aditya 1-1-1997 8766655433

1BM14CS002 Bharath 31-12-1996 9762255433 7066722433

Student Table Mobile Table


USN Mobile
USN Name DOB
1BM14CS001 8766655433
1BM14CS001 Aditya 1-1-1997
1BM14CS002 9762255433
1BM14CS002 Bharath 31-12-1996
1BM14CS002 7066722433
Friday, August 28, 2020 CSE, KL UNIVERSITY 77
Converting ER diagram to Tables
 Multi-Valued Attributes
USN DOB
Name
Primary
Key Mobile
Student

Student Table Mobile Table


USN Mobile
USN Name DOB Foreign
1BM14CS001 8766655433
1BM14CS001 Aditya 1-1-1997 Key
1BM14CS002 9762255433
1BM14CS002 Bharath 31-12-1996
1BM14CS002 7066722433

If you have a multi-valued attribute, take the attribute and turn it into a
new entity or table of its own. Then make a 1:N relationship between
the new entity and the existing one. In simple words,
1.Create a table for the attribute.
2.Add the primary (id) column of the parent entity as a foreign key
within the new table
Friday, August 28, 2020 CSE, KL UNIVERSITY 78
Converting ER diagram to Tables
Street Area
 Composite Attribute Name Name

Address Place
USN DOB
Name

Student Mobile

Friday, August 28, 2020 CSE, KL UNIVERSITY 79


Converting ER diagram to Tables
Street Area
 Composite Attribute Name Name

Address Place
USN DOB
Name

Student Mobile

Student Table
USN Name DOB Street Area Place
1BM14CS001 Aditya 1-1-1997 RK Road Nagar Mandya

1BM14CS002 Bharath 31-7-1996 S V Road Layout Kolar

USN Mobile
Mobile Table 1BM14CS001 8766655433

1BM14CS002 9762255433

1BM14CS002 7066722433
Friday, August 28, 2020 CSE, KL UNIVERSITY 80
Converting ER diagram to Tables
Street Area
 Derived Attribute Name Name

Address Place
USN DOB
Name

Age Student Mobile

Student Table
USN Name DOB Street Area Place
1BM14CS001 Aditya 1-1-1997 RK Road Nagar Mandya

1BM14CS002 Bharath 31-7-1996 S V Road Layout Kolar

USN Mobile
Mobile Table 1BM14CS001 8766655433

1BM14CS002 9762255433

1BM14CS002 7066722433
Friday, August 28, 2020 CSE, KL UNIVERSITY 81
Converting ER diagram to Tables
 Relationship: One-to-One

D-ID
F-ID 1
1
F-Name
D-Name

Friday, August 28, 2020 CSE, KL UNIVERSITY 82


Converting ER diagram to Tables
 Relationship: One-to-One
D-ID
F-ID 1
1
F-Name
D-Name

Approach 1: Foreign Key


Faculty Table Department Table
F-ID F-Name
D- D-Name Heading
1 Dr. H S Guruprasad ID F-ID
2 Dr. Umadevi V 10 CSE 1
3 Dr. Gowrishankar 20 ISE 3

Friday, August 28, 2020 CSE, KL UNIVERSITY 83


Converting ER diagram to Tables
 Relationship: One-to-One
D-ID
F-ID 1
1
F-Name
D-Name

Approach 1: Foreign Key


Department Table
Primary Primary Foreign
Key Faculty Table Key Key
F-ID F-Name
D- D-Name Heading
1 Dr. H S Guruprasad ID F-ID
2 Dr. Umadevi V 10 CSE 1
3 Dr. Gowrishankar 20 ISE 3

Friday, August 28, 2020 CSE, KL UNIVERSITY 84


Converting ER diagram to Tables
 Relationship: One-to-One
D-ID
F-ID 1
1
F-Name
D-Name
Approach 2: Merged Relation approach
Merging two entity types and relationship into one single relation.
This may be appropriate when both participations are total

Faculty –Department Table


F- F-Name D-ID D-Name HOD
ID
1 Dr. H S Guruprasad 10 CSE Yes
2 Dr. Umadevi V 10 CSE No
3 Dr. Gowrishankar 20 ISE Yes
Friday, August 28, 2020 CSE, KL UNIVERSITY 85
Converting ER diagram to Tables
 Relationship: One-to-One
D-ID
F-ID
1 1

F-Name
D-Name
Approach 3: Cross-reference or relationship relation approach

Faculty Table Department Table HOD Table


F-ID F-Name D- D-Name D-ID F-ID
1 Dr. H S Guruprasad ID
10 1
2 Dr. Umadevi V 10 CSE
20 3
3 Dr. Gowrishankar 20 ISE
Lookup Table

Friday, August 28, 2020 CSE, KL UNIVERSITY 86


Converting ER diagram to Tables
 Relationship: One-to-Many

USN
D-ID
Departme 1 Has M
Student
nt
D-Name
S-Name

Friday, August 28, 2020 CSE, KL UNIVERSITY 87


Converting ER diagram to Tables
 Relationship: One-to-Many
USN
D-ID
Departme 1 Has M
Student
nt
D-Name
S-Name
Approach 1 Student Table
Department Table USN S-Name D-ID
D-ID D-Name 1BM14CS001 Akash 10
10 CSE 1BM14CS002 Bharath 10

20 ISE 1BM14CS003 Ragu 10


1BM14CS004 Mohan 20
1BM14CS005 Nikil 20

Friday, August 28, 2020 CSE, KL UNIVERSITY 88


Converting ER diagram to Tables
 Relationship: One-to-Many
USN
D-ID
Departme 1 Has M
Student
nt
D-Name
S-Name
Approach 2 Student Table Department
Department Table USN S-Name Student Table
USN D-ID
D-ID D-Name 1BM14CS001 Akash
1BM14CS002 Bharath 1BM14CS001 10
10 CSE
1BM14CS003 Ragu 1BM14CS002 10
20 ISE
1BM14CS004 Mohan 1BM14CS003 10
1BM14CS005 Nikil 1BM14CS004 20
1BM14CS005 20
Friday, August 28, 2020 CSE, KL UNIVERSITY 89
Converting ER diagram to Tables

 Relationship: Many-to-Many

USN C-ID
Enrolls_for
Student Course
S-Name C-Name
Friday, August 28, 2020 CSE, KL UNIVERSITY 90
Converting ER diagram to Tables
 Relationship: Many-to-Many
USN C-ID
Enrolls_for
Student Course
S-Name C-Name

Student Table Course Table Student


Course Table
USN S-Name C-ID C-Name
USN C-ID
1BM14CS001 Avinash 10 DBMS
1BM14CS001 10
1BM14CS002 Balaji 20 Java
1BM14CS001 20
1BM14CS003 Chandan
1BM14CS002 20
1BM14CS003 10

Friday, August 28, 2020 CSE, KL UNIVERSITY 91


Converting ER diagram to Tables
 Relationship: Many-to-Many
USN C-ID
Enrolls_for
Student Course
S-Name C-Name

Student Table Course Table Student


Course Table
USN S-Name C-ID C-Name
USN C-ID
1BM14CS001 Avinash 10 DBMS
1BM14CS001 10
1BM14CS002 Balaji 20 Java
1BM14CS001 20
1BM14CS003 Chandan
1BM14CS002 20
1BM14CS003 10

Friday, August 28, 2020 CSE, KL UNIVERSITY 92


Converting ER diagram to Tables
Partial Name
Key -----

F-ID F-Name

Faculty
Dependents_of Dependent

Owner
Identifying Weak
Entity
Relationship Entity

Friday, August 28, 2020 CSE, KL UNIVERSITY 93


Converting ER diagram to Tables
Partial Name
 Weak Entity Key -----

F-ID F-Name

Faculty
Dependents_of Dependent

Owner
Identifying Weak
Entity
Relationship Entity

Faculty Table Dependent Table

F-ID F-Name F-ID Dependent


Name
10 Dr. Guruprasad 10 Ram
20 Dr. Gowrishankar 10 Ravi
20 Ram

Friday, August 28, 2020 CSE, KL UNIVERSITY 94


Activity To Do
Convert the Following ER diagram to Database table schema

1 M

M M 1

N
N
M

Friday, August 28, 2020 CSE, KL UNIVERSITY 95


Database tables or Schema Diagram
Musician Table
Name Muscian-ID
Album Table
Album-ID Copyright Format Title Producer
Date ID

Song Table
Song-ID Author Title Album-ID

Performing Table
Muscian-ID Song-ID
Plays Table
Muscian-ID Instr-ID
Instrument Table
Instr-ID Name M-Key

Friday, August 28, 2020 CSE, KL UNIVERSITY 96


Database tables or Schema Diagram
Musician Table
Name Muscian-ID
Album Table
Album-ID Copyright Format Title Producer
Date ID

Song Table
Song-ID Author Title Album-ID

Performing Table
Muscian-ID Song-ID
Plays Table
Muscian-ID Instr-ID

Instrument Table
Instr-ID Name M-Key

Friday, August 28, 2020 CSE, KL UNIVERSITY 97


Thanks for Listening

Friday, August 28, 2020 CSE, KL UNIVERSITY 98


Cardinality Ratios
 Cardinality is a constraint on a relationship specifying the
number of entity instances that a specific entity may be related
to via the relationship.
Many to One:
More than one entities from entity set A can be associated with at
most one entity of entity set B, however an entity from entity
set B can be associated with more than one entity from entity
set A.

N R 1
Entity A Entity B

Friday, August 28, 2020 CSE, KL UNIVERSITY 99

You might also like