Professional Documents
Culture Documents
DBMS 4th Unit Questions With Answers
DBMS 4th Unit Questions With Answers
Define and explain about redundancy and the problems that it can cause
Or
Discuss various problems that arise with redundant storage of Information?
Here all the data is stored in a single table which causes redundancy of data or say anomalies
as SID and Sname are repeated once for same CID . Let us discuss anomalies one by one. Due
to redundancy of data we may get the following problems, those are
1.insertion anomalies : It may not be possible to store some information unless some other
information is stored as well.
2.redundant storage: some information is stored repeatedly
3.update anomalies: If one copy of redundant data is updated, then inconsistency is created
unless all redundant copies of data are updated.
4.deletion anomalies: It may not be possible to delete some information without losing some
other information as well. Problem in updation / updation anomaly – If there is updation in
the fee from 5000 to 7000, then we have to update FEE column in all the rows, else data will
become inconsistent.
Insertion Anomaly and Deletion Anomaly- These anomalies exist only due to redundancy,
otherwise they do not exist.
Insertion Anomalies: New course is introduced C4, But no student is there who is having C4
Subject
Deletion Anomaly: Deletion of S3 student cause the deletion of course. Because of deletion
of some data forced to delete some other useful data
2. What is the need for normalization of schemas? Are they any demerits of normalization?
Purpose of Normalization:
Remove insert, update, and delete anomalies during the database activities.
Normalization reduces a complex user view to a set of small and sub groups of fields or
relations. This process helps to design a logical data model known as conceptual data
model.
Advantages of Normalization:
4. The database & application design processes are much for flexible.
5. Security is easier to maintain or manage.
Disadvantages of Normalization:
1. The disadvantage of normalization is that it produces a lot of tables with a relatively small
number of columns. These columns then have to be joined using their primary/foreign key
relationship.
Performance: all the joins required to merge data slow processing & place additional stress on
your hardware.
Complex queries: developers have to code complex queries in order to merge data from different
tables.
Properties of Decomposition
1. Lossless Decomposition
Decomposition must be lossless. It means that the information should not get lost from the
relation that is decomposed.
It gives a guarantee that the join will result in the same relation as it was decomposed.
2. Dependency Preservation
Dependency is an important constraint on the database.
Every dependency must be satisfied by at least one decomposed table.
If {A → B} holds, then two sets are functional dependent. And, it becomes more useful for
checking the dependency easily if both sets in a same relation.
This decomposition property can only be done by maintaining the functional dependency.
In this property, it allows to check the updates without computing the natural join of the
database structure.
3. Lack of Data Redundancy
Lack of Data Redundancy is also known as a Repetition of Information.
The proper decomposition should not suffer from any data redundancy.
The careless decomposition may cause a problem with the data.
The lack of data redundancy property may be achieved by Normalization process.
4. Explain 1NF, 2NF, and 3NF with suitable examples?
First Normal Form (1NF): A relation is said to in the 1NF if it is already in un-normalized
form and it satisfies the following conditions or rules or qualifications are:
1. Each attribute name must be unique.
2. Each attribute value must be single or atomic i.e., Single Valued Attributes.
3. Each row / record must be unique.
4. There is no repeating group’s.
Example: How do we bring an un-normalized table into first normal form? Consider the
following relation:
Solution: This table is not in first normal form because the [Color] column can contain
multiple values. For example, the first row includes values "red" and "green." To bring this
table to first normal form, we split the table into two tables and now we have the resulting
tables:
Second Normal Form (2NF): A relation is said to be in 2NF, if it is already in 1st NF and it
has no Partial Dependency i.e., no non-prime attribute is dependent on the only a part of the
candidate key.
(OR)
A relation is in second normal form if it satisfies the following conditions:
• It is in first normal form
• All non-key attributes are fully functional dependent on the primary key.
Note: Partial Functional Dependency: If a non-prime attribute of the relation is getting
derived by only a part of the candidate key, then such dependency is known as Partial
Dependency
Example: Consider the following relation
➔This table has a composite primary key [Customer ID, Store ID]. The non-key attribute is
[Purchase Location]. In this case, [Purchase Location] only depends on [Store ID], which is
only part of the primary key. Therefore, this table does not satisfy second normal form.
➔ To bring this table to second normal form, we break the table into two tables, and now we
have the following
Third Normal Form (3NF): A database is in third normal form if it satisfies the following
conditions:
• It is in 2NF.
• There is no transitive functional dependency
By transitive functional dependency, we mean we have the following relationships in
the table: A is functionally dependent on B, and B is functionally dependent on C. In
this case, C is transitively dependent on A via B. and A non-key attribute is
depending on a non-key attribute.
Example: Consider the following relation.
➔ In the table able, [Book ID] determines [Genre ID], and [Genre ID] determines [Genre
Type].
Therefore, [Book ID] determines [Genre Type] via [Genre ID] and we have transitive
functional dependency, and this structure does not satisfy third normal form.
➔ To bring this table to third normal form, we split the table into two as follows:
5. Give a set of FDs for the relation schema R(A, B, C, D) with primary key AB under which R is in
1NF but not in 2NF.
Sol: R=ABCD
Key=AB
(a) Atomic values are allowed in 1NF and partial dependency is not allowed in 2NF.
The following FDs are allowed.
BC, AC, BD, AD
(show the FDs which is having partial dependency)
(b) According to question partial dependencies are not allowed and transitivity
dependency is allowed. The following FDs are allowed.
CD, DC
Consider a schema R(A,B,C,D) and functional dependencies A->B and C->D which is decomposed into
R1(AB) and R2(CD)
Example
Let a relation R(A,B,C,D) and set a FDs F = { A -> B , A -> C , C -> D} are given.
so, F' = F.
The Closure Of Functional Dependency means the complete set of all possible attributes that can be
functionally derived from given functional dependency using the inference rules known as
Armstrong’s Rules.
If “F” is a functional dependency then closure of functional dependency can be denoted using “{F}+”.
There are three steps to calculate closure of functional dependency. These are:
Step-1 : Add the attributes which are present on Left Hand Side in the original functional
dependency.
Step-2 : Now, add the attributes present on the Right Hand Side of the functional dependency.
Step-3 : With the help of attributes present on Right Hand Side, check the other attributes that can
be derived from the other given functional dependencies. Repeat this process until all the possible
attributes which can be derived are added in the closure.
Example 1: Find candidate keys for the relation R(ABCD) having following FD’s ABCD, CA, DA.
Sol: From the given FD’s, the attribute B is key attribute because it is not in RHS of functional
dependency.
BD+ = BDA (∵ D A )
CD+ = CDA (∵ D A )
AC+ = AC
AD+ =AD
From the above attributes AB and BC determines all attributes. AB, BC are candidate keys.
8. When is the decomposition of a relational schema R into two relational schemas X and Y said
to be lossless-join decomposition? Why is this property so important? Give a necessary and
sufficient condition to test whether a decomposition is lossless-join
Decomposition of a Relation-
The process of breaking up or dividing a single relation into two or more sub relations is called as
decomposition of a relation.
Properties of Decomposition-
The following two properties must be followed when decomposing a given relation-
1. Lossless decomposition-
2. Dependency Preservation-
Types of Decomposition-
Example-
A B C
1 2 1
2 5 3
3 3 3
R( A , B , C )
Consider this relation is decomposed into two sub relations R1( A , B ) and R2( B , C )-
A B
1 2
2 5
3 3
R1( A , B )
B C
2 1
5 3
3 3
R2( B , C )
Now, if we perform the natural join ( ⋈ ) of the sub relations R1 and R2 , we get-
A B C
1 2 1
2 5 3
3 3 3
NOTE-
Example-
A B C
1 2 1
2 5 3
3 3 3
R( A , B , C )
Consider this relation is decomposed into two sub relations as R1( A , C ) and R2( B , C )-
R1( A , B )
A C
1 1
2 3
3 3
B C
2 1
R2( B , C )
5 3
3 3
R1 ⋈ R2 ⊃ R
Now, if we perform the natural join ( ⋈ ) of the sub relations R1 and R2 we get-
A B C
1 2 1
2 5 3
2 3 3
3 5 3
3 3 3
This relation is not same as the original relation R and contains some extraneous tuples.
NOTE-
Then,
Condition-01:
Union of both the sub relations must contain all the attributes that are present in the original
relation R.
Thus,
R1 ∪ R2 = R
Condition-02:
Intersection of both the sub relations must not be null.
In other words, there must be some common attribute which is present in both the sub
relations.
Thus,
R1 ∩ R2 ≠ ∅
Condition-03:
Intersection of both the sub relations must be a super key of either R 1 or R2 or both.
Thus,
Consider a relation schema R ( A , B , C , D ) with the functional dependencies A → B and C →
D. Determine whether the decomposition of R into R1 ( A , B ) and R2 ( C , D ) is lossless or
lossy.
Solution-
Condition-01:
According to condition-01, union of both the sub relations must contain all the attributes of
relation R.
So, we have-
=R(A,B,C,D)
Clearly, union of the sub relations contain all the attributes of relation R.
Condition-02:
According to condition-02, intersection of both the sub relations must not be null.
So, we have-
=Φ
Problem-02:
B→C
C→D
D→B
Consider the original relation R was decomposed into the given sub relations as shown-
According to condition-01, union of both the sub relations must contain all the attributes of
relation R.
So, we have-
=R(A,B,C,D)
Clearly, union of the sub relations contain all the attributes of relation R.
Condition-02:
According to condition-02, intersection of both the sub relations must not be null.
So, we have-
=B
Condition-03:
According to condition-03, intersection of both the sub relations must be the super key of one of
the two sub relations or both.
So, we have-
B+ = { B , C , D }
Now, we see-
Attribute ‘B’ can not determine attribute ‘A’ of sub relation R’.
Thus, it is not a super key of the sub relation R’.
Attribute ‘B’ can determine all the attributes of sub relation R 3.
Thus, it is a super key of the sub relation R 3.
Clearly, intersection of the sub relations is a super key of one of the sub relations.
9. Define multivalued dependencies and join dependencies. Discuss the use of such
dependencies in database design.
When we want to test the relations or decide if these happen to be lawful under some
arrangement of practical as well as multivalued dependencies.
When we want to determine what limitations are there on the arrangement of the lawful
relations. Thus, we will concern ourselves with just the relations that fulfil a given
arrangement of practical as well as multivalued dependencies.
Dependency plays key role in differentiating good database design from bad database designs.
the key”.
In other words, a dependency FD: “X → Y” means that the values of Y are determined by the
values of X. Two tuples sharing the same values of X will necessarily have the same values of
Attributes which are parts of any candidate key of relation are called as prime attribute, others
Candidate Key: Candidate Key is minimal set of attributes of a relation which can be used to
identify a tuple
uniquely.
Super Key: Super Key is set of attributes of a relation which can be used to identify a tuple
uniquely.
11. Consider the schema R=(A,B,C,D,E) and the functional dependencies: A→BC, CD→E, B→D,
E→A. Give a lossless join decomposition into BCNF of the schema R.
Soultion:
result : = {R};
F
+ = {A → ABCDE, B → D, BC → ABCDE, CD → ABCDE, E → ABCDE, …}.
R is not in BCNF.
B → D is a non-trivial f.d. that holds on R, B ∩ D = ∅, and B → ABCDE is not in
F
+
. Therefore,
result := (result – R) ∪ (R – D) ∪ (B, D), i.e. (A, B, C, E) ∪ (B, D).
(A, B, C, E) and (B,D) are in BCNF. So this is a decomposition of R into BCNF.
12. Consider the relational schema R(A, B, C), which has the FD: B → C. If A is a candidate key for
R, is it possible for R to be in BCNF? If so, under what conditions? If not, explain why not.
Soultion:
If A is the candidate key for the given relation then the non trivial dependency that will be
implied is :
A --> BC as we know candidate key is a key that uniquely identifies a tuples hence determines
all attributes value
So prime attribute : A
since for BCNF we require that every determinant (left hand side of FD) must be a superkey
which is not the case here.
A superkey is nothing but superset of candidate key (or) we can say candidate key is the
minimal superkey.
Solution: