6 Relational Database Design
6 Relational Database Design
Redundancy:
• Data for branch_name, branch_city, assets are repeated for each loan that provides
by bank.
• Storing information several times leads waste of storage space / time.
• Data redundancy leads problem in Insertion, deletion and update.
Insertion problem
• We cannot store information about a branch without loan information, we can use
null values for loan information, but they are difficult to handle.
Deletion problem
• In this example, if we delete the information of Manoj (i.e. DELETE FROM
branch_loan WHERE customer_name = ‘Manoj’;), we cannot obtain the
information of pokhara branch (i.e. we don’t know branch city of pokhara, total
asset of pokhara branch etc.
Update problem
• Since data are duplicated so multiple copies of same fact need to update while
updating one. It increases the possibility of data inconsistency. When we made
update in one copy there is possibility that only some of the multiple copies are
update but not all, which lead data/database in inconsistent state..
©T Paneru 1
For more notes visit https://collegenote.pythonanywhere.com
6.0 Relational Database Design
6.2 Decomposition
The idea of decomposition is break down large and complicated r elation in no. of simple and
small relations which minimized data redundancy. It can be consider principle to solve the
relational model problem.
Definition
The decomposition of relation schema R= (A 1, A2, . ,An) is a set of relation schema { R 1, R2, ---
-- Rm}, such that Ri ⊆ R ∀ 1 ≤ i ≤ m and R1 U R2 U . . U Rm = R.
That is all attributes of an original schema (R) must appear in the decomposition (R 1, R2).
That is, R= R1 U R2. if R ≠ R1 U R2 then such decomposition called lossey join decomposition.
That is, R ≠ ∏R1(R) ∏R2(R). Decomposition should lossless join decomposition.
A decomposition of relation schema R into R 1 and R2 is lossless join iff at least one of the
following dependencies is in F +.
R1 I R2→R1
R1 I R2→R2
Example 1: The problems in the relational schema branch_loan (illustrated in above example)
can be resolved if we replace it with the following relation schemas.
Example 2: Consider the relation schema to store t he information a student maintain by the
university.
Student_info (#name, course, phone_no, major, prof, grade)
Problems:
Redundancy:
• Data for major and phone_no of student are stored several times in the database
once for each course that is taken by a student.
Complicates updating:
• Multiple copies of some facts may lead to update which leads possibility of
inconsistency.
• Here, change of phone_no of John is required we need to update three records
(tuples) corresponding to the student John. If one of the three tuples is not changed
there will be inconsistency in the date.
©T Paneru 2
For more notes visit https://collegenote.pythonanywhere.com
6.0 Relational Database Design
Complicate insertion
• If this is only the relation in the database showing the association between a faculty
member and the course he / she teaches, then the information that a given professor is
teaching a given course cannot be entered in the database unless a student is registered
in the course.
Deletion Problem:
• If the only one student is registered in a given course then the information as to which
professor is of fering the course will be lost if this is only the relation in the database
showing the association between the faculty member and the course he / she teaches. If
database have another relation that establishes the relationship between a course, the
deletion of 4th & 5th tuple in this relation will not cause the information about the
councils teach to be lost.
Solution?
⇒ Decomposition
The problems in this relation schema student_info can be resolved if we it with the following
relation schemas.
Students (#name, phone_no, major)
Transcript (#name, course, grade)
Teacher (course, prof)
• Here, first relat ion sche ma gives the phone number and major subject of each student
such information will be stored only once for each student. Thus, any changes in the
phone number will thus require changes in only one tuple of this relation
• The second relation schema ‘TRANSCRIP’ stores the grade of each student in each
course. So, to insert information about student phone number, major and the course
teaches by which the professor.
• Third relation schema records the teacher of each course.
©T Paneru 3
For more notes visit https://collegenote.pythonanywhere.com
6.0 Relational Database Design
6.3 Normalization:
A relation is said to in particular normal form if it satisfy the set of this particular normal form if
it satisfy the set of this particular normal form’s constraints. In practical, third normal form is
sufficient to design reliable database system.
©T Paneru 4
For more notes visit https://collegenote.pythonanywhere.com
6.0 Relational Database Design
Example:
faculty prof course
course_name department
X DBMS Computer
Software Computer
computer Engineering
Microprocessor Electronics
Y Mathematical Math
Analysis
Probability Theory Stat
Z Modern Physic Physics
Physics Z Dynamics Physics
P Vector Analysis Math
Figure: non-normalized relation
• Here, the attribute of relation schema, that is course is divided into course_name and
department. That is, domain of attribute course is non atomic.
• Here, each row contains multiple set of values.
6.3.5 Key and non key attribute (prime and non prime attribute)
• Here, name and course are key attributes and phone_no, major and department are non
key attribute.
©T Paneru 5
For more notes visit https://collegenote.pythonanywhere.com
6.0 Relational Database Design
Data redundancy
o Given professor assigned to corres ponding faculty is repeated a number of times.
o Given course offered by correspondi ng department is repeated number of times.
o Data redundancy leads problem in insertion, deletion and update.
Update problem
o If professor change faculty to teach then we must change all rows where that
professor appears, it may leads inconsistency in database.
Deletion problem
o If we have to delete the professor who teach only one subject (course_name) in such
case deletion cause the loss of information about the department to which the course
belongs.
Insertion problem
o Suppose department i ntroduce new course (i.e. course_name) such information can
not insert without professor name and assigned faculty. This is possible inserting
only null values instead of professor name and his/her assigned faculty.
©T Paneru 6
For more notes visit https://collegenote.pythonanywhere.com
6.0 Relational Database Design
Student-general-info
F={name→phone_no,name→major}
Phone_no and major are fully functional dependent on key ‘name’ of relation schema ‘student-
general-info’. So the is in 2NF. Moreover, here is no functional dependency between non key
attributes (phone_no & major). So this relation is also in 3NF (discuss later)
Transcript
F={name,course→grade}
Here grade is fully functionally dependent on relation key (name, course). So this relation is in
2NF. Moreover, here is no fu nctional dependency between non key attributes because here is
only one non key attribute grade.
Teacher
F={course→prof}
Here. Prof is fully functionally dependent on relation key course. So this relation is in 2NF.
Moreover, here is no functional dependency between non key attributes. Here is only one non
key attributes prof.
©T Paneru 7
For more notes visit https://collegenote.pythonanywhere.com
6.0 Relational Database Design
Course_room_info=(course,room)
Fds=no functional dependency exist because course and room both are here
foreign key.
Course_detail=(#course,prof,room,room_capacity,enroll_limit)
Fds={course→(prof,room,room_capacity,enroll_limit),room→room_capacity}
Relations in 2NF
Course_detail=(#course,prof,room,emroll_limit)
FDs={course→prof,course→room,course→enroll_limit,room→enroll_limit}
Room_detail=(#room,room_capacity)
Fds={room→room_capacity}
Relations in 3NF
Course_prof_info=(#course.prof,enroll_limit)
FDs={course→prof, course→enroll_limit}
Course_room_info=(course,room)
No FDs
Room_detail=(#room,room_capacity)
FDs={room→eoom_capacity}
©T Paneru 8
For more notes visit https://collegenote.pythonanywhere.com
6.0 Relational Database Design
• Assume that , each student has unique name and unique student_id then set of FD
FDs={name,course →grade,
student_id,course→grade,name→student_id,student_id→name}
• Here this rela tion has two candidate keys {name,course} and {student_id,course}. Each of
those composite key has common attribute course.
• Here the relation grade is not in BCNF because the dependencies
{student_id→name}and {name→student_id} are non trivial and there determinants are not
superkey of relation grade.
These problems of relation schema i n 3NF occ ur since relation may have overlapping candidate
keys. BCNF removes this problem. So it is stronger than 3NF.
where student_id, name and phone_no assumed to be unique in this relation. The following FDs
satisfy this relation.
FDs={student_id→name,student_id→phone_no,student_id→major, name→student_id,
name→phone_no, name→major,
phone_no→student_id,phone_no→name,phone_no→major}
Here each non trivial FD involves candidate key as determinant. Hence the relation
‘student_info’ is in BCNF.
©T Paneru 9
For more notes visit https://collegenote.pythonanywhere.com