0% found this document useful (0 votes)
377 views

Solutions To DBMS Assignment II R13

The document discusses database normalization through four normal forms: 1) First normal form requires each table contain a primary key and no repeating columns. 2) Second normal form removes redundant data in rows. 3) Third normal form ensures each column is dependent on the primary key only. 4) Fourth normal form represents many-to-many relationships using separate junction tables. The document uses an example of a student-pet database to illustrate how it can be normalized through these forms.

Uploaded by

jyothibellaryv
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
377 views

Solutions To DBMS Assignment II R13

The document discusses database normalization through four normal forms: 1) First normal form requires each table contain a primary key and no repeating columns. 2) Second normal form removes redundant data in rows. 3) Third normal form ensures each column is dependent on the primary key only. 4) Fourth normal form represents many-to-many relationships using separate junction tables. The document uses an example of a student-pet database to illustrate how it can be normalized through these forms.

Uploaded by

jyothibellaryv
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

ADITYA COLLEGE OF

ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING

ASSIGNMENT - II
Due Date : 9th April, 2016
1. What are the demerits of relational database design. Describe the problems
caused by redundancy. (Raghu ramakrishnan Pg.No.418, Sudarsan Korth
Pg.No: 258,Ullman 102-103).
Pitfalls in Relational-Database Design
Among the undesirable properties that a bad design may have are:
Repetition of information
Inability to represent certain information
Problems Caused by Redundancy
Storing the same information redundantly, that is, in more than one place within a
database, can lead to several problems:
Redundant storage: Some information is stored repeatedly.
Update anomalies: If one copy of such repeated data is updated, an inconsistency
is created unless all copies are similarly updated.
Insertion anomalies: It may not be possible to store some information unless some
other information is stored as well.
Deletion anomalies: It may not be possible to delete some information without
losing some other information as well.
2. Define Normalization and explain about the properties of decomposition.
(Raghu ramakrishnan Pg.No.419,434,Korth Pg.No: 274-282).
Database normalization is the process of making the data in a database available
in the most organized way possible.When youre normalizing a database, there are
two things you need to consider: whether the information in the database has
internal redundancies, and whether the dependencies across the different tables in
the database are logically organized.The term normalization comes from the
concept of normal forms, which describe just how organized the information is in
the database. As an example, lets imagine were creating a database of the
children in a class, and the pets they have. When starting to build this database,
the first approach might be to create a simple table with all of the information in
one place, and one row for each student.

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
TABLE: STUDENTS

| Name

| Age | Pet | Pet Name |

---------------------------------------------| Heather

| 10

| Dog | Rex

---------------------------------------------| Rachel

| 10

| Cat | Fluff

---------------------------------------------| Jimmy

| 11

| Dog | Kimba

---------------------------------------------| Lola

| 1o

| Cat | Thomas

----------------------------------------------

First Normal Form


To achieve first normal form for a database, you need to make sure that no table
contains multiple columns that you could use to get the same information. Each
table should be organized into rows, and each row should have a primary key that
distinguishes it as unique. The primary key is usually a single column, but
sometimes more than one column can be combined to create a single primary key.
Using the rules of first normal form, there may be redundant information across
multiple rows, but each row will be unique.
TABLE: STUDENTS

| Name

| Age | Pet | Pet Name |

----------------------------------------------

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
| Heather

| 10

| Dog | Rex

---------------------------------------------| Heather

| 10

| Cat | Thomas

---------------------------------------------| Rachel

| 10

| Cat | Fluff

---------------------------------------------| Jimmy

| 11

| Dog | Kimba

---------------------------------------------| Lola

| 10

| Cat | Thomas

----------------------------------------------

Second Normal Form


In this first example there are two rows for Heather, with changes to the second
row to show the fact that there are multiple pets. While this is searchable, and
follows first normal form, it is an inefficient use of space. To achieve second normal
form, it would be helpful to split out the pets into an independent table, and match
them up using the student names as foreign keys.
TABLE: STUDENTS

| Name

| Age |

----------------------------| Heather

| 10

----------------------------| Rachel

| 10

-----------------------------

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
| Jimmy

| 11

----------------------------| Lola

| 10

-----------------------------

TABLE: PETS

| Type

| Pet Name

| Owner

--------------------------------------| Dog

| Rex

| Heather

--------------------------------------| Cat

| Thomas

| Heather

--------------------------------------| Cat

| Fluff

| Rachel

--------------------------------------| Dog

| Kimba

| Jimmy

--------------------------------------| Cat

| Thomas

| Lola

---------------------------------------

Third Normal Form


This is a cleaner organization for the information, and avoids repeating the age of
the student with two pets, but the dogs and cats are repeated several times in the
pets table. We can see that it is uncertainty when there are two pets with the
same type and the same name. Is the primary key the owner and the type, the

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
name and the type, or the owner and the name? Third normal form would suggest
making sure each non-key element in each table provides information about the
key in the row.
In order to establish an unambiguous unique identifier for each pet, it is useful to
include a unique primary key that distinguishes each pet from the others. A similar
issue could occur if there were two students with the same name, so creating
unique primary key values for the student table is also a good idea. Often these
will be added automatically when database rows are set to autoincrement.
TABLE: STUDENTS

| ID | Name

| Age |

---------------------------------| 00 | Heather

| 10

---------------------------------| 01 | Rachel

| 10

---------------------------------| 02 | Jimmy

| 11

---------------------------------| 03 | Lola

| 10

----------------------------------

TABLE: PETS

| ID | Type

| Pet Name

| Owner ID |

--------------------------------------------

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
| 00 | Dog

| Rex

| 00

-------------------------------------------| 01 | Cat

| Thomas

| 00

-------------------------------------------| 02 | Cat

| Fluff

| 01

-------------------------------------------| 03 | Dog

| Kimba

| 02

-------------------------------------------| 04 | Cat

| Thomas

| 03

--------------------------------------------

Fourth Normal Form


Now it is clear that which pet and which student are associated, the fact that one
student may have more than one pet, or that one pet may be shared among more
than one student, needs to be represented. For this example, imagine that we
needed to show that the cat named Thomas as actually shared between Lola and
Heather. To represent this clearly, we need to add a third table of relationships.
TABLE: STUDENTS

| ID | Name

| Age |

---------------------------------| 00 | Heather

| 10

---------------------------------| 01 | Rachel

| 10

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
---------------------------------| 02 | Jimmy

| 11

---------------------------------| 03 | Lola

| 10

----------------------------------

TABLE: PETS

| ID | Type

| Pet Name

--------------------------------| 00 | Dog

| Rex

--------------------------------| 01 | Cat

| Thomas

--------------------------------| 02 | Cat

| Fluff

--------------------------------| 03 | Dog

| Kimba

---------------------------------

Table: PETS-STUDENTS

| Pet ID | Owner ID |

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
--------------------| 00

| 00

--------------------| 01

| 00

--------------------| 02

| 01

--------------------| 03

| 02

--------------------| 01

| 03

---------------------

Now we have a flexible and searchable structure in fourth normal form that can
represent all the available information about each of the students, each of the
pets, and the relationships among them.
3. Define Functional Dependency and closure of a functional dependency.
Describe various rules of closure of functional dependencies. (Raghu
ramakrishnan Pg.No.422-430 ,Ullman Pg.No. 83-84,90-95 Sudarsan Korth
Pg.No: 263).
Functional dependency is a relationship that exists when one attribute uniquely
determines another attribute. If R is a relation with attributes X and Y, a functional
dependency between the attributes is represented as X->Y, which specifies Y is
functionally dependent on X.
Closure of a Functional Dependency Set F, F+: If F is a set of functional
dependencies for a relation R, the set. of functional dependencies that can be
derived from F, F+, is called the CLOSURE of F. Amstrong's axiom are sufficient to
compute all of F+.

1. To compute

, we can use some rules of inference called Armstrong's Axioms:

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
o Reflexivity rule: if is a set of attributes and
o Augmentation rule: if
holds.
o Transitivity rule: if

, then

holds.

holds, and is a set of attributes, then

holds, and

holds, then

holds.

2. These rules are sound because they do not generate any incorrect functional
dependencies. They are also complete as they generate all of
.
3. To make life easier we can use some additional rules, derivable from Armstrong's
Axioms:
o Union rule: if

and

o Decomposition rule: if
o Pseudotransitivity rule: if

, then
holds, then
holds, and

holds.
and

both hold.

holds, then

holds.

4. a. Define : Candidate Key, Super Key and Key. (Raghu ramakrishnan


Pg.No.422-430 ,Ullman Pg.No. 84-88, Korth Pg.No: 93-94).
b. What is multi valued dependency. Describe 4NF and 5NF. (Raghu
ramakrishnan Pg.No.445 ,Ullman Pg.No. 118-125, Sudarsan Korth Pg.No: 292).
c. What is denormalization. Which normal form is adequate for a good
database design. (Sudarsan Korth Pg.No: 296).
In computing, denormalization is the process of attempting to optimize the read
performance of a database by adding redundant data or by grouping data.
5.a. Explain various relational algebraic operations with suitable examples. (Raghu
ramakrishnan Pg.No.92 ,Ullman Pg.No. 192, Sudarsan Korth Pg.No: 97).

Relational database systems are expected to be equipped with a query language that can assist
its users to query the database instances. There are two kinds of query languages relational
algebra and relational calculus.

Relational Algebra
Relational algebra is a procedural query language, which takes instances of relations as input
and yields instances of relations as output. It uses operators to perform queries. An operator can
be either unary or binary. They accept relations as their input and yield relations as their
output. Relational algebra is performed recursively on a relation and intermediate results are
also considered relations.

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
The fundamental operations of relational algebra are as follows

Select

Project

Union

Set different

Cartesian product

Rename

We will discuss all these operations in the following sections.

Select Operation
It selects tuples that satisfy the given predicate from a relation.
Notation pr r
Where stands for selection predicate and r stands for relation. p is prepositional logic formula
which may use connectors like and, or, and not. These terms may use relational operators like
=, , , < , >, .
For example
subject

(Books)

= "database"

Output Selects tuples from books where subject is 'database'.


subject

(Books)

= "database" and price = "450"

Output Selects tuples from books where subject is 'database' and 'price' is 450.
subject

(Books)

= "database" and price = "450" or year > "2010"

Output Selects tuples from books where subject is 'database' and 'price' is 450 or those books
published after 2010.

Project Operation

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
It projects columns s that satisfy a given predicate.
Notation A1, A2, An r r
Where A1, A2 , An are attribute names of relation r.
Duplicate rows are automatically eliminated, as relation is a set.
For example
subject,

author

(Books)

Selects and projects columns named as subject and author from the relation Books.

Union Operation
It performs binary union between two given relations and is defined as
r s = { t | t r or t s}
Notion r U s
Where r and s are either database relations or relation result set
temporaryrelation temporaryrelation .
For a union operation to be valid, the following conditions must hold

r, and s must have the same number of attributes.

Attribute domains must be compatible.

Duplicate tuples are automatically eliminated.

author

(Books)

author

(Articles)

Output Projects the names of the authors who have either written a book or an article or
both.

Set Difference
The result of set difference operation is tuples, which are present in one relation but are not in
the second relation.

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
Notation r s
Finds all the tuples that are present in r but not in s.

author

(Books)

author

(Articles)

Output Provides the name of authors who have written books but not articles.

Cartesian Product X
Combines information of two different relations into one.
Notation r s
Where r and s are relations and their output will be defined as
r s = { q t | q r and t s}
author

(Books Articles)

= 'tutorialspoint'

Output Yields a relation, which shows all the books and articles written by tutorialspoint.

Rename Operation
The results of relational algebra are also relations but without any name. The rename operation
allows us to rename the output relation. 'rename' operation is denoted with small Greek letter
rho .
Notation x E E
Where the result of expression E is saved with name of x.
Additional operations are

Set intersection

Assignment

Natural join

Relational Calculus

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
In contrast to Relational Algebra, Relational Calculus is a non-procedural query language, that
is, it tells what to do but never explains how to do it.
Relational calculus exists in two forms

Tuple Relational Calculus TRC TRC


Filtering variable ranges over tuples
Notation {T | Condition}
Returns all tuples T that satisfies a condition.
For example
{ T.name |

Author(T) AND T.article = 'database' }

Output Returns tuples with 'name' from Author who has written article on 'database'.
TRC can be quantified. We can use Existential and Universal Quantifiers .
For example
{ R| T

Authors(T.article='database' AND R.name=T.name)}

Output The above query will yield the same result as the previous one.

Domain Relational Calculus DRC


In DRC, the filtering variable uses the domain of attributes instead of entire tuple values
asdoneinTRC,mentionedabove
Notation
{ a1, a2, a3, ..., an | P (a1, a2, a3, ... ,an)}
Where a1, a2 are attributes and P stands for formulae built by inner attributes.
For example
{< article, page, subject > |

TutorialsPoint subject = 'database'}

ADITYA COLLEGE OF
ENGINEERING
VALASAPALLE(P), PUNGANUR ROAD, MADANAPALLE 517325

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
Output Yields Article, Page, and Subject from the relation TutorialsPoint, where subject is
database.
Just like TRC, DRC can also be written using existential and universal quantifiers. DRC also
involves relational operators.
The expression power of Tuple Relation Calculus and Domain Relation Calculus is equivalent
to Relational Algebra.

You might also like