Dbms - II Unit
Dbms - II Unit
The total number of attributes in a relation is known as the degree of the relation. This is also
called as ‘arity’.
The STUDENT relation defined above has degree 7.
Characteristics of Relations:
• Tuples in a relation do not have any specified order.
• Ordering of values within a tuple is significant.
• Each tuple in a relation contains a single value for each of its attribute.
• No two tuples are identical in a relation.
Tuple : A tuple is a single row in a database that contains a single record for such a relation.
A row or record is another name for a single item in a table, which is what a triple is.
Attribute : Attributes are the properties which define a relation. For example, in a customer
database, the attributes might be name, address, and phone number.
Domain : A domain D is a set of atomic values. Each simple attribute of entity type is
associated with domain of values which specifies set of values that can be assigned to that
attribute for individual entity.
For example: In the Student table, for (Roll_No, ID, Name), Roll_No and ID are candidate keys
as they will contain unique values only.
A referential integrity constraint is specified between two tables and is used to maintain
the consistency among tuples of the two tables. It states that ‘a tuple in one relation that refers to
another relation must refer to an existing tuple in that relation’.
A referential integrity constraint is specified between two tables and is used to maintain
the consistency among tuples of the two tables. It states that ‘a tuple in one relation that refers to
another relation must refer to an existing tuple in that relation’. The widely used referential
constraint is foreign key.
11. Give any two basic operations that can change the state of relations in the database.
(i) Insert: This operation is performed to add a new tuple in a relation.
(ii) Delete: This operation is carried out to remove a tuple from a relation.
12. What is the function of Insert, update and delete functions?
Insert: This operation is performed to add a new tuple in a relation.
Delete: This operation is carried out to remove a tuple from a relation.
Update: This operation is used to update or modify existing values of record in a data table.
13. Mention any two update anomalies.
(i) Insertion Anomaly: If there is a new row inserted in the table and it creates the inconsistency
in the table then it is called the insertion anomaly.
(ii) Deletion Anomaly: If we delete some rows from the table and if any other information or data
which is required is also deleted from the database, this is called the deletion anomaly in the
database.
3 OR MORE MARKS
1. Discuss Domains and attributes with respect to relational scheme?
Relation schema defines the design and structure of the relation. It consists of the relation name,
set of attributes/field names/column names. Every attribute would have an associated domain.
Domain: Each simple attribute of entity type is associated with domain of values which specifies
set of values that can be assigned to that attribute for individual entity. For example, If the range
of ages allowed for employees is between 20 and 60 , we can specify domain for age to be set of
integers between 20 and 70.
A data type or format is also specified for each domain. For example, The data type for
Employee_ages is an integer number between 15 and 80. A domain is thus given a name, data
type, and format.
Attribute: It contains the name of a column in a particular table. Each attribute Ai must have a
domain, dom(Ai).
A relation schema R, denoted by R(A1, A2, ..., An), is made up of a relation name R and a list of
attributes, A1, A2, ..., An. The degree (or arity) of a relation is the number of attributes of its
relation schema. A relation of degree five, which stores information about students, would contain
five attributes describing each student as follows:
STUDENT(RollNo, Name, Home_phone, Address, Age)
For this relation schema, STUDENT is the name of the relation, which has five attributes. We can
specify previously defined domains for some of the attributes of the STUDENT relation:
dom(RollNo)= rollno; dom(Name)=Names; dom(HomePhone)= phone_no;
Given above is a STUDENT relation. Each tuple in the relation represents a particular student
entity. The relation is displayed as a table where each tuple is shown as a row.
(i) Unique
Sometimes we need to maintain only unique data in the column of a database table, this is
possible by using a unique constraint. Unique constraint ensures that all values in a column are
unique.
Eg:
CREATE TABLE Persons (
ID int UNIQUE,
Name varchar(255) NOT NULL,
Age int,
);
We are not supposed to enter the data that is already present in ID column.
(ii) Check
Check constraint ensures that the data entered by the user for that column is within the range of
values or possible values specified.
Eg:
CREATE TABLE STUDENT (
ID int ,
Name varchar(255) ,
Age int,
CHECK (Age<=18)
);
the only possible values that the age column will accept is [0 -17].
7. Explain the three basic operations that can change the states of relations in the database?
(i) Insert: This operation is performed to add a new tuple in a relation. The insert operation is capable of
violating constraints.
Eg:
(ii) Delete: This operation is carried out to remove a tuple from a relation. A particular data record from
a table can be removed by performing such operation. The delete operation can violate only referential
integrity, if tuple being removed is referenced by foreign key from other tuples in the database.
Eg:
(iii) Modify: The operation aims at causing a change in the values of some attributes in existing tuples.
This is useful in modifying existing values of record in a data table. Usually, this operation does not cause
problems only if the modification is directed on neither primary key nor foreign key. Whenever applied,
these operations must enforce integrity constraints specified on relational database schema.
Eg:
Anomaly means the inconsistency occurred in the relational table during the operations performed
on the relational table.
Eg:
Deletion Anomaly
If we delete some rows from the table and if any other information or data which is required is also
deleted from the database, this is called the deletion anomaly in the database.
Eg : If we want to delete the department number ECT669 then the details of Rajesh will also be
deleted since Rajesh's details are dependent on the row of ECT669.
Modification Anomaly
When we change the value of one attribute of a row in the table, and if it leads to the inconsistency
of the table then this anomaly occurs.
Eg: If we want to update the address of Ramesh then we will have to update all the rows where
Ramesh is present.
In some schema designs, we may group many attributes together into a one relation. If many of
the attributes do not apply to all tuples in the relation, we end up with many NULLs in those
tuples. This can waste space at the storage level and may also lead to problems with
understanding the meaning of the attributes.
Another problem with NULLs is how to account for them when aggregate operations such as
COUNT or SUM are applied. As SELECT and JOIN operations involve comparisons, if NULL
values are present, the results may become unpredictable. Moreover, NULLs can have multiple
interpretations, such as the following:
• The attribute does not apply to this tuple. For example, Visa_status may not apply to U.S.
students.
• The attribute value for this tuple is unknown. For example, the Date_of_birth may be
unknown for an employee.
• The value is known but absent; that is, it has not been recorded yet. For example, the
Phone_Number for an employee may exist, but may not be available and recorded yet.
Having the same representation for all NULLs compromises the different meanings they may
have.
In this example, if we know the value of Employee id, we can obtain Employee Name and
Salary. We can say that the Employee Name and Salary are functionally depended on Employee
id.
Types:
• Trivial functional dependency
In Trivial Functional Dependency, a dependent is always a subset of the determinant.
i.e. If X → Y and Y is the subset of X, then it is called trivial functional dependency.
Eg:
Here, {roll_no, name} → name is a trivial
Roll_no Name Age
functional dependency, since the dependent
42 Abc 17
name is a subset of determinant set {roll_no,
43 Pqr 18
name}
44 xyz 18
Similarly, roll_no → roll_no is also an example
of trivial functional dependency.
The second normal form is based on the full functional dependency. A relation is said to be in
2NF if it is first in 1NF and all non-key attributes are fully functional dependent on the primary
key.i.e. no partial dependency exists.
Second Normal Form applies to relations with composite keys, that is, relations with a primary
key composed of two or more attributes.
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 a part
of the primary key. Therefore, this table does not satisfy second normal form.
To bring this table to second normal form, we have to break the table into two tables as
shown below:
Now, in the table TABLE_STORE, the column Purchase Location is fully dependent on the
primary key of that table, which is Store ID.
o A relation will be in 3NF if it is in 2NF and not contain any transitive partial dependency.
o 3NF is used to reduce the data duplication. It is also used to achieve the data integrity.
o If there is no transitive dependency for non-prime attributes, then the relation must be in
third normal form.
A relation is in third normal form if it holds atleast one of the following conditions for every
non-trivial function dependency X → Y.
1. X is a super key.
2. Y is a prime attribute, i.e., each element of Y is part of some candidate key.
In the above table, 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 3NF, we split the table into two as follows:
Now all non-key attributes are fully functional dependent only on the primary key. In
TABLE_BOOK, both Genre ID and Price are only dependent on Book ID. In
TABLE_GENRE, Genre Type is only dependent on Genre ID.
18. Given below are two sets of FDs for a relation R(A,B,C,D,E) are they equivalent?
(i) A→B, AB→C, D→AC, D→E
(ii) A→BC, D→AE
Let F1 = { A→B, AB→C, D→AC, D→E}
F2 = {A→BC, D→AE}
19. A set of FDs for the relation R {A, B, C, D, E, F} is AB→C, C→A, BC→D, ACD→B,
BE→C, EC→FA, CF→BD, D→E. Find a minimum cover for this set of FDs.
20. Prove that any relation schema with two attributes is in BCNF.
If there is a relation schema with two attributes say R(A,B) then if either of the attribute
becomes the key let say A be the key, then A->B is true. So R is in BCNF.
Otherwise both of them is the key then {A,B} -> {A,B}, so BCNF holds.
Proof:
Let a, b be the two attributes in a relation R. The possible functional dependencies are:
Case 1: LHS contains both attributes
a b -> ---
Clearly this is a trivial functional dependency because RHS attributes form subset of LHS
attributes .
Case 2 : LHS contains only one attribute.
a->---
b->---
Clearly in this case, the LHS attribute will be candidate key.
Hence the possible functional dependencies are either trivial or the LHS attributes form a
superkey. So, the relation having only two attributes will be in BCNF.
21.Prove and disprove the following inference rules for functional dependencies.
The following six rules IR1 through IR6 are well-known inference rules for functional
dependencies:
IR1 (reflexive rule)1: If X ⊇ Y, then X →Y.
Eg: X = {a, b, c, d, e}
Y = {a, b, c}
IR2 (augmentation rule)2: {X → Y} |=XZ → YZ.
Eg: For R(ABCD), if A → B then AC → BC
IR3 (transitive rule): {X → Y, Y → Z} |=X → Z.
Example:
R=(A,C,D,E,H)
F1={A->C, AC->D, E->AD, E->H},
F2={A->CD, E->AH}
Check whether F1 and F2 are equivalent or not?
Solution:
To check F1 covers F2 −
A+={A,C,D} contains C,D
E+={A,D,E,H} contains A,H
So F1 covers F2
The formal definition is: A set of FD F to be minimal if it satisfies the following conditions −
Step 3: {AC->D}
{A}+ = {A, C}
Therefore, C is extraneous and is removed.
{A->D}
From above arrow diagram on R, we can see that an attributes AB is not determined by any
of the given FD, hence AB will be the integral part of the Candidate key.
Since R has 4 attributes: - A, B, C, D, and Candidate Key is AB, Therefore, prime attributes
(part of candidate key) are A and B while a non-prime attribute are C and D.
a) FD: AB → CD satisfies the definition of 2NF, that non-prime attribute(C and D) are fully
dependent on candidate key AB
b) FD: B → C does not satisfy the definition of 2NF, as a non-prime attribute(C) is partially
dependent on candidate key AB( i.e. key should not be broken at any cost)
Since FD: B → C, our table was not in 2NF, let's decompose the table
R1(B, C)
Since the key is AB, and from FD AB → CD, we can create R2(A, B, C, D) but this will
again have a problem of partial dependency B → C, hence R2(A, B, D).
a) R1( B, C) b) R2(A, B, D)
a) FD: PQ → R does not satisfy the definition of 2NF, that non-prime attribute( R) is
partially dependent on part of candidate key PQS.
b) FD: S → T does not satisfy the definition of 2NF, as a non-prime attribute(T) is partially
dependent on candidate key PQS (i.e., key should not be broken at any cost).
Since due to FD: PQ → R and S → T, our table was not in 2NF, let's decompose the table
And create one table for the key, since the key is PQS.
R3(P, Q, S)
1. FD: PQ → R does not satisfy the definition of 2NF, that non-prime attribute( R) is
partially dependent on part of candidate key PQS
2. FD: PS → VW does not satisfy the definition of 2NF, that non-prime attribute( VW)
is partially dependent on part of candidate key PQS
3. FD: QS → TU does not satisfy the definition of 2NF, that non-prime attribute( TU) is
partially dependent on part of candidate key PQS
4. FD: P → X does not satisfy the definition of 2NF, that non-prime attribute( X) are
partially dependent on part of candidate key PQS
5. FD: W → Y does not violate the definition of 2NF, as the non-prime attribute(Y) is
dependent on the non-prime attribute(W), which is not related to the definition of
2NF.
Since due to FD
: PQ → R, PS → VW, QS → TU, P → X our table was not in 2NF, let's decompose the table
R6(P, Q, S)
FD: X → Y is in 2NF ( as Key is not breaking and its Fully functional dependent )
FD: Y → Z is also in 2NF( as it does not violate the definition of 2NF)
Convert the table R( X, Y, Z) into 3NF:
Since due to FD: Y → Z, our table was not in 3NF, let's decompose the table
FD: Y → Z was creating issue, hence one table R1(Y, Z).
Create one Table for key X, R2(X, Y), since X → Y.
1. FD: X → Y does not satisfy the definition of 3NF, that neither X is Super Key nor Y
is a prime attribute.
2. FD: Y → P does not satisfy the definition of 3NF, that neither Y is Super Key nor P is
a prime attribute.
3. FD: Z → W satisfies the definition of 3NF, that neither Z is Super Key nor W is a
prime attribute.
Convert the table R( X, Y, Z, W, P) into 3NF:
Since all the FD = { X → Y, Y → P, and Z → W} were not in 3NF, let us convert R in 3NF
R1(X, Y) {Using FD X → Y}
R2(Y, P) {Using FD Y → P}
R3(Z, W) {Using FD Z → W}
All the decomposed tables R1, R2, R3, and R4 are in 2NF( as there is no partial dependency)
as well as in 3NF.