Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

Chameli Devi Group of Institutions

Department of Computer Science and Engineering


Class: Fifth Semester B.Tech. (CSE)
Subject: Database Management System (CS502)
Session (July –Dec 2019-20)

DBMS CS 502 Question Bank

Q1. Explain different types of Relational integrity constraints in RDBMS.

Solution: There are three main integrity constraints −

 Key constraints
 Domain constraints
 Referential integrity constraints
Key Constraints
There must be at least one minimal subset of attributes in the relation, which can identify a tuple
uniquely. This minimal subset of attributes is called key for that relation. If there is more than
one such minimal subset, these are called candidate keys.
Key constraints force that −
 In a relation with a key attribute, no two tuples can have identical values for key attributes.
 A key attribute cannot have NULL values.
Key constraints are also referred to as Entity Constraints.
Domain Constraints
Attributes have specific values in real-world scenario. For example, age can only be a positive
integer. The same constraints have been tried to employ on the attributes of a relation. Every
attribute is bound to have a specific range of values. For example, age cannot be less than zero
and telephone numbers cannot contain a digit outside 0-9.
Referential integrity Constraints
Referential integrity constraints work on the concept of Foreign Keys. A foreign key is a key
attribute of a relation that can be referred in other relation.
Referential integrity constraint states that if a relation refers to a key attribute of a different or
same relation, then that key element must exist.

Q2. Discuss 2NF with suitable examples and tables.

Solution: Second normal form (2NF)


A table is said to be in 2NF if both the following conditions hold:
 Table is in 1NF (First normal form)
 No non-prime attribute is dependent on the proper subset of any candidate key of table.
An attribute that is not part of any candidate key is known as non-prime attribute.
Example: Suppose a school wants to store the data of teachers and the subjects they teach. They
create a table that looks like this: Since a teacher can teach more than one subjects, the table can
have multiple rows for a same teacher.
Teacher_id subject teacher_age
111 Maths 38
111 Physics 38
222 Biology 38
333 Physics 40
333 Chemistry 40

Candidate Keys: {teacher_id,subject}


Non-prime attribute: teacher_age
The table is in 1 NF because each attribute has atomic values. However, it is not in 2NF because
non-prime attribute teacher_age is dependent on teacher_id alone which is a proper subset of
candidate key. This violates the rule for 2NF as the rule says “no non-prime attribute is
dependent on the proper subset of any candidate key of the table”.
To make the table complies with 2NF, we can break it in two tables like this
teacher_details table:

teacher_id teacher_age
111 38
222 38
333 40
teacher_subject table:

teacher_id subject
111 Maths
111 Physics
222 Biology
333 Physics
333 Chemistry

Now the tables comply with Second normal form (2NF).


Q3. Explain the following: a) Database schema b) Intension c) Extension

Solution: A database schema is the skeleton structure that represents the logical view of the
entire database. It defines how the data is organized and how the relations among them are
associated. It formulates all the constraints that are to be applied on the data.

A database schema defines its entities and the relationship among them. It contains a descriptive
detail of the database, which can be depicted by means of schema diagrams. It’s the database
designers who design the schema to help programmers understand the database and make it
useful.

A database schema can be divided broadly into two categories −

Physical Database Schema − This schema pertains to the actual storage of data and its form of
storage like files, indices, etc. It defines how the data will be stored in a secondary storage.

Logical Database Schema − This schema defines all the logical constraints that need to be
applied on the data stored. It defines tables, views, and integrity constraints.

Intension
The intension is the schema of the relation and thus is independent of the time as it does not
change once created. So, it is the permanent part of the relation and consists of –
1. Naming Structure – Naming Structure includes the name of the relation and the attributes of
the relation.
2. Set of Integrity Constraints – The Integrity Constraints are divided into Integrity Rule 1 (or
entity integrity rule), Integrity Rule 2 (or referential integrity rule), key constraints, domain
constraints etc.
For example:
Employee (EmpNo Number (4) NOT NULL, EName Char(20), Age Number(2), Dept
Char(4)

Extension
The set of tuples appearing at any instant in a relation is called the extension of that relation. In
other words, instance of Schema is the extension of a relation. The extension varies with time as
instance of schema or the value in the database will change with time.

Q4. Explain inner join with the help of examples. Also, explain the need of theta join?

Solution: INNER JOIN: The INNER JOIN keyword selects all rows from both the tables as
long as the condition satisfies. This keyword will create the result-set by combining all rows
from both the tables where the condition satisfies i.e value of the common field will be same.
Syntax:
SELECT table1.column1,table1.column2,table2.column1,....
FROM table1
INNER JOIN table2
ON table1.matching_column = table2.matching_column;

table1: First table.


table2: Second table
matching_column: Column common to both the tables.

This query will show the names and age of students enrolled in different courses.

SELECT StudentCourse.COURSE_ID, Student.NAME, Student.AGE FROM Student


INNER JOIN StudentCourse
ON Student.ROLL_NO = StudentCourse.ROLL_NO;

Output:

Q5. What is normalization? Discuss the need for normalization with examples.

Solution: Normalization is a database design technique which organizes tables in a manner that
reduces redundancy and dependency of data. It divides larger tables to smaller tables and link
them using relationships.
If a database design is not perfect, it may contain anomalies, which are like a bad dream for any
database administrator. Managing a database with anomalies is next to impossible.
 Update anomalies − If data items are scattered and are not linked to each other properly, then
it could lead to strange situations. For example, when we try to update one data item having its
copies scattered over several places, a few instances get updated properly while a few others
are left with old values. Such instances leave the database in an inconsistent state.
 Deletion anomalies − We tried to delete a record, but parts of it was left undeleted because of
unawareness, the data is also saved somewhere else.
 Insert anomalies − We tried to insert data in a record that does not exist at all.
Normalization is a method to remove all these anomalies and bring the database to a consistent
state.
Here are the most commonly used normal forms:
 First normal form(1NF)
 Second normal form(2NF)
 Third normal form(3NF)
 Boyce & Codd normal form (BCNF)

Q6. Discuss the following with examples:

i) Null values And Dangling tuples ii) Multivalued Dependency

Solution: i) Null Values: The SQL NULL is the term used to represent a missing value. A NULL
value in a table is a value in a field that appears to be blank. A field with a NULL value is a field
with no value.
A null value is placed in a field of a table when a specific value is either unknown or inappropriate.
Here it is unknown. A slightly different meaning would be if warehouse manager also had a percent
(commission) field, but since warehouse managers don't get commissions, would get null value.

A null value can be used for either a numeric or character type. BUT IT HAS A DIFFERENT VALUE
FROM ANY REAL FIELD. In particular, it is not zero (0) or the null string (''). It is handled specially
by commercial databases.

Dangling tuples: An attribute of the join operator is that it is possible for certain tuples to be
"dangling"; that is, they fail to match any tuple of the other relation in the common attributes.
Dangling tuples do not have any trace in the result of the join, so the join may not represent the
data of the original relations completely.

ii) Multivalued dependency occurs when there are more than one independent multivalued
attributes in a table, a multivalued dependency is a full constraint between two sets of attributes
in a relation.
In contrast to the functional dependency, the multivalued dependency requires that
certain tuples be present in a relation. Therefore, a multivalued dependency is a special case
of tuple-generating dependency. The multivalued dependency plays a role in the 4NF database
normalization.
A multivalued dependency is a special case of a join dependency, with only two sets of values
involved, i.e. it is a binary join dependency.
For example: Consider a bike manufacture company, which produces two colors (Black and white) in
each model every year.
bike_model manuf_year Color

M1001 2007 Black

M1001 2007 Red

M2012 2008 Black


M2012 2008 Red

M2222 2009 Black

M2222 2009 Red

Here columns manuf_year and color are independent of each other and dependent on
bike_model. In this case these two columns are said to be multivalued dependent on bike_model.
These dependencies can be represented like this:
bike_model ->> manuf_year
bike_model ->> color

Q7. What is Functional Dependency? How to find FD’s for a relation?

Solution: A functional dependency A->B in a relation holds if two tuples having same value of
attribute A also have same value for attribute B. For Example, in relation STUDENT shown in
table 1, Functional Dependencies
STUD_NO->STUD_NAME, STUD_NO->STUD_ADDR hold

but

STUD_NAME->STUD_ADDR do not hold

To find functional dependencies for a relation.

Functional Dependencies in a relation are dependent on the domain of the relation. Consider the
STUDENT relation given in Table 1.

 We know that STUD_NO is unique for each student. So STUD_NO->STUD_NAME,


STUD_NO->STUD_PHONE, STUD_NO->STUD_STATE, STUD_NO-
>STUD_COUNTRY and STUD_NO -> STUD_AGE all will be true.
 Similarly, STUD_STATE->STUD_COUNTRY will be true as if two records have same
STUD_STATE, they will have same STUD_COUNTRY as well.
 For relation STUDENT_COURSE, COURSE_NO->COURSE_NAME will be true as
two records with same COURSE_NO will have same COURSE_NAME.

Q8. Differentiate between Relational Algebra and Relational Calculus.

Solution:

S.NO Relational Algebra Relational Calculus


While Relational Calculus is Declarative
1. It is a Procedural language.
language.
Relational Algebra means how to obtain While Relational Calculus means what
2.
the result. result we have to obtain.
In Relational Algebra, The order is
While in Relational Calculus, The order is
3. specified in which the operations have to
not specified.
be performed.
Relational Algebra is independent on While Relation Calculus can be a domain
4.
domain. dependent.
Relational Algebra is nearer to a While Relational Calculus is not nearer to
5.
programming language. programming language.

Q9. Discuss different types of keys in relational model with suitable examples.

Solution: Candidate Key: The minimal set of attribute which can uniquely identify a tuple is
known as candidate key. For Example, STUD_NO in STUDENT relation.

 The value of Candidate Key is unique and non-null for every tuple.
 There can be more than one candidate key in a relation. For Example, STUD_NO as well
as STUD_PHONE both are candidate keys for relation STUDENT.
 The candidate key can be simple (having only one attribute) or composite as well. For
Example, {STUD_NO, COURSE_NO} is a composite candidate key for relation
STUDENT_COURSE.

Super Key: The set of attributes which can uniquely identify a tuple is known as Super Key. For
Example, STUD_NO, (STUD_NO, STUD_NAME) etc.

 Adding zero or more attributes to candidate key generates super key.


 A candidate key is a super key but vice versa is not true.

Primary Key: There can be more than one candidate key in a relation out of which one can be
chosen as primary key. For Example, STUD_NO as well as STUD_PHONE both are candidate
keys for relation STUDENT but STUD_NO can be chosen as primary key (only one out of many
candidate keys).
Alternate Key: The candidate key other than primary key is called as alternate key. For
Example, STUD_NO as well as STUD_PHONE both are candidate keys for relation STUDENT
but STUD_PHONE will be alternate key (only one out of many candidate keys).

Foreign Key: If an attribute can only take the values which are present as values of some other
attribute, it will be foreign key to the attribute to which it refers. The relation which is being
referenced is called referenced relation and corresponding attribute is called referenced attribute
and the relation which refers to referenced relation is called referencing relation and
corresponding attribute is called referencing attribute. Referenced attribute of referenced relation
should be primary key for it. For Example, STUD_NO in STUDENT_COURSE is a foreign key
to STUD_NO in STUDENT relation.

It may be worth noting that unlike, Primary Key of any given relation, Foreign Key can be
NULL as well as may contain duplicate tuples i.e. it need not follow uniqueness constraint.

For Example, STUD_NO in STUDENT_COURSE relation is not unique. It has been repeated
for the first and third tuple. However, the STUD_NO in STUDENT relation is a primary key and
it needs to be always unique and it cannot be null.

Q10. Differentiate between Partial dependency and transitive dependency.

Solution: (a) Partial Dependency


If a non-prime attribute of the relation is getting derived by only a part of the composite
candidate key then such dependency is defined as partial dependency.
(1) While identifying the partial dependencies we shall verify that the dependent must be a non-
prime attribute and the determinant must be a part of candidate key.
(2) In order to have partial dependency in a relation, it should have atleast one composite
candidate key.
(3) Partial dependency will cause redundancy and hence it will get eliminated by normalization
technique.

b) Transitive Dependency
If a non-prime attribute of the relation is getting derived by either another non-prime attribute or
the combination of part of the candidate key along with a non-prime attribute then such
dependency would be defined as transitive dependency.

(1) While identifying the transitive dependency make sure that the dependent is a non-prime
attribute and the determinant could be either a non-prime attribute or the combination of part of
the candidate key along with non-prime attribute.
(2) Transitive dependency will cause redundancy in the relation and hence it will get eliminated
by normalization technique.

You might also like