DBMS Imp question
DBMS Imp question
1
What is data independence?
Ans-> Data independence is a property of a database management system by which we
can change the database schema at one level of the database system without changing
the database schema at the next higher level. Through data independence, we can build
an environment in which data is independent of all programs, and through the three
schema architectures, data independence will be more understandable.
Types of Data Independence
There are two types of data independence.
• logical data independence
• Physical data independence
Q.2
Q.3
For example, if there is a lot of redundant data present in our database then DBMS
anomalies can occur. If a table is constructed in a very poor manner then there is a chance
of database anomaly. Due to database anomalies, the integrity of the database suffers.
The other reason for the database anomalies is that all the data is stored in a single table.
So, to remove the anomalies of the database, normalization is the process which is done
where the splitting of the table and joining of the table occurs.
Example 1:
Updation Anomaly
When we update some rows in the table, and if it leads to the inconsistency of the table
then this anomaly occurs. This type of anomaly is known as an updation anomaly. In the
above table, if we want to update the address of Ramesh then we will have to update all
the rows where Ramesh is present. If during the update we miss any single row, then
there will be two addresses of Ramesh, which will lead to inconsistent and wrong
databases.
3
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. For example, if in the above table, we create a new
row of a worker, and if it is not allocated to any department then we cannot insert it in
the table so, it will create an insertion anomaly.
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. For example, in the above table, 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. So, there will be deletion anomalies in the table.
Q.7 Explain the following terms: a) Functional dependency b) Prime and Non-
prime attribute.
Ans-> Functional dependency : The functional dependency is a relationship that exists
between two attributes. It typically exists between the primary key and non-key attribute
within a table. X → Y
Emp_Id → Emp_Name
We can say that Emp_Name is functionally dependent on Emp_Id.
4
Here, {roll_no, name} → name is a trivial functional dependency, since the
dependent name is a subset of determinant set {roll_no, name}. Similarly, roll_no
→ roll_no is also an example of trivial functional dependency.
2. Non-trivial functional dependency
o A → B has a non-trivial functional dependency if B is not a subset of A.
o When A intersection B is NULL, then A → B is called as complete non-trivial.
o Example:
Delete doesn’t DROP the whole TRUNCATE first drops the table &
table. It acquires a lock on table then re-create it, which is faster than
and starts deleting the rows. deleting individual rows.
6
Q.11 Explain cardinality ratio with example.
Ans-> In a database, the mapping cardinality or cardinality ratio means to denote the
number of entities to which another entity can be linked through a certain relation set.
Mapping cardinality is most useful in describing binary relation sets.
Types of cardinality in between tables are:
• One-to-One
• One-to-Many
• Many-to-One
• Many-to-Many
One-to-One
In this type of cardinality mapping, an entity in A is connected to at most one entity in B.
For example, in a particular hospital, the surgeon department has one head of
department. They both serve one-to-one relationships.
One-to-Many
In this type of cardinality mapping, an entity in A is associated with any number of
entities in B.For example, in a particular hospital, the surgeon department has
multiple doctors. They serve one-to-many relationships.
Many-to-One
In this type of cardinality mapping, an entity in A is connected to at most one entity in
B. For example, In a particular hospital, multiple surgeries are done by a single
surgeon. Such a type of relationship is known as a many-to-one relationship.
7
Many-to-Many
In this type of cardinality mapping, an entity in A is associated with any number of entities
in B, and an entity in B is associated with any number of entities in A. For example, In a
particular company, multiple people work on multiple projects. They serve many-to-many
relationships.
BCNF (Boyce-Codd Normal Form) is considered stronger than 3NF (Third Normal Form)
because BCNF eliminates more redundancy by enforcing a stricter rule: every functional
dependency in a relation must have a superkey on the left side, whereas 3NF only
requires that non-key attributes be fully dependent on each candidate key, allowing for
potential redundancy in certain scenarios where there are multiple candidate
keys; essentially, every BCNF table is also a 3NF table, but not every 3NF table is BCNF.
Q.13 Explain about Loss less-join dependency?
Ans-> Decomposition of a relation is done when a relation in a relational model is not in
appropriate normal form. Relation R is decomposed into two or more relations if
decomposition is lossless join as well as dependency preserving.
Lossless Join Decomposition
If we decompose a relation R into relations R1 and R2,
Decomposition is lossy if R1 ⋈ R2 ⊃ R
Decomposition is lossless if R1 ⋈ R2 = R
8
To check for lossless join decomposition using the FD set, the following conditions must
hold:
1. The Union of Attributes of R1 and R2 must be equal to the attribute of R. Each attribute
of R must be either in R1 or in R2.
Att(R1) U Att(R2) = Att(R)
2. The intersection of Attributes of R1 and R2 must not be NULL.
Att(R1) ∩ Att(R2) ≠ Φ
3. The common attribute must be a key for at least one relation (R1 or R2)
Att(R1) ∩ Att(R2) -> Att(R1) or Att(R1) ∩ Att(R2) -> Att(R2)
For Example, A relation R (A, B, C, D) with FD set{A->BC} is decomposed into R1(ABC) and
R2(AD) which is a lossless join decomposition as:
1. First condition holds true as Att(R1) U Att(R2) = (ABC) U (AD) = (ABCD) = Att(R).
2. Second condition holds true as Att(R1) ∩ Att(R2) = (ABC) ∩ (AD) ≠ Φ
3. The third condition holds as Att(R1) ∩ Att(R2) = A is a key of R1(ABC) because
A->BC is given.
9
Ans-> Locking protocols are used in database management systems as a means of
concurrency control. Multiple transactions may request a lock on a data item
simultaneously. Hence, we require a mechanism to manage the locking requests made by
transactions. Such a mechanism is called a Lock Manager. It relies on the process of
message passing where transactions and lock manager exchange messages to handle the
locking and unlocking of data items.
1. Shared lock:
o It is also known as a Read-only lock. In a shared lock, the data item can only read
by the transaction.
o It can be shared between the transactions because when the transaction holds a
lock, then it can't update the data on the data item.
2. Exclusive lock:
o In the exclusive lock, the data item can be both reads as well as written by the
transaction.
o This lock is exclusive, and in this lock, multiple transactions do not modify the
same data simultaneously.
Atomicity
o ○ The phrase “all or nothing” describes the first ACID property i.e. atomicity.
10
o It states that all operations of the transaction take place at once if not, the
transaction is aborted.
o There is no midway, i.e., the transaction cannot occur partially. Each transaction is
treated as one unit and either run to completion or is not executed at all.
Consistency
o The phrase “no violation of integrity constraints” describes the property of
consistency.
o The integrity constraints are maintained so that the database is consistent before
and after the transaction.
o The consistent property of database states that every transaction sees a consistent
database instance.
o The transaction is used to transform the database from one consistent state to
another consistent state.
For example: The total amount must be maintained before or after the transaction.
o Total before T occurs = 600+300=900
o Total after T occurs= 500+400=900
Isolation
o It shows that the data which is used at the time of execution of a transaction
cannot be used by the second transaction until the first one is completed.
o In isolation, if the transaction T1 is being executed and using the data item X, then
that data item can't be accessed by any other transaction T2 until the transaction
T1 ends.
o The concurrency control subsystem of the DBMS enforced the isolation property.
Durability:
This property ensures that once the transaction has completed execution, the updates
and modifications to the database are stored in and written to disk and they persist even
if a system failure occurs. These updates now become permanent and are stored in non-
volatile memory.
Ans->
Shared lock can be placed on objects Exclusive lock can only be placed on
that do not have an exclusive lock objects that do not have any other
already placed on them. kind of lock.
11
Any number of transaction can hold Exclusive lock can be hold by only
shared lock on an item. one transaction.
Ans-> Relational algebra is a procedural query processing language that provides the base
of relational databases and SQL. Relational algebra has various operators like select,
project, rename, cartesian product, union, intersection, set difference, joins, etc. These
operators are used to form queries in relational algebra.
The operations that operate on only one relation are called unary operations in
relational algebra. The three unary operations in relational algebra are:
• Selection
• Projection
• Rename
Student
1 A 80
2 B 50
3 C 95
4 D 62
5 A 70
12
Q.1: Output all the tuples of the relation.
σ (Student)
Q.3: Retrieve only those tuples where either Marks less than 70 or Studentname
is A.
Q.4: Retrieve the tuples with Student Name A and Marks greater than 75.
πRollno(Student)
Q.7: Retrieve the Rollno of students whose Marks is greater than or equal to 80.
Example 2: Predict the output of given queries. Consider the below relation.
Employee
201 P 20000
202 Q 5000
13
203 R 10000
204 P 7500
Output:
Employee
201 P 20000
202 Q 5000
203 R 10000
204 P 7500
Output:
Employee
201 P 20000
204 P 7500
Q.3: πEname(Employee)
Output:
Ename
14
Q
Q.4: ρ E (id, name, S) πEid, Ename, Salary [σSalary > 10000 (Employee)]
Output:
id name S
201 P 20000
Q.24 Define the term data redundancy and data Inconsistency.
Ans-> It is defined as redundancy means duplicate data and it is also stated that the same
parts of data exist in multiple locations in the database. This condition is known as Data
Redundancy.
Example –
15
Data Inconsistency: When the same data exists in different formats in multiple tables. This
condition is known as Data Inconsistency. It means that different files contain different
information about a particular object or person. This can cause unreliable and meaningless
information. Data Redundancy leads to Data Inconsistency.
Example –
If we have an address of someone in many tables and when we change it in only one table
and in another table it may not be updated so there is the problem of data inconsistency
may occur.
16
Valid Reference:
• When inserting into the Employee table, DeptID must exist in the Department table.
Invalid Reference:
• Inserting an Employee with a DeptID not present in the Department table will result
in an error.
QUESTION NO
Long Answer Type Questions
Explain generalization, specialization and aggregation.
Q.1
Describe different states of transaction.
Ans-> In DBMS, a transaction passes through various states such as active, partially
committed, failed, and aborted. Understanding these transaction states is crucial for
database management and ensuring the consistency of data.
Q.2
1. Active State – When the instructions of the transaction are running then the
transaction is in active state. If all the ‘read and write’ operations are performed
without any error then it goes to the “partially committed state”; if any instruction
fails, it goes to the “failed state”.
2. Partially Committed – After completion of all the read and write operation the
changes are made in main memory or local buffer. If the changes are made
permanent on the DataBase then the state will change to “committed state” and in
case of failure it will go to the “failed state”.
3. Failed State – When any instruction of the transaction fails, it goes to the “failed
state” or if failure occurs in making a permanent change of data on Database.
4. Aborted State – After having any type of failure the transaction goes from “failed
state” to “aborted state” and since in previous states, the changes are only made to
local buffer or main memory and hence these changes are deleted or rolled-back.
17
5.Committed State – It is the state when the changes are made permanent on the
Data Base and the transaction is complete and therefore terminated in the
“terminated state”.
6.Terminated State – If there isn’t any roll-back or the transaction comes from the
“committed state”, then the system is consistent and ready for new transaction and
the old transaction is terminated.
42 abc 17
43 pqr 18
44 xyz 18
42 abc CO 4
43 pqr EC 2
44 xyz IT 1
45 abc EC 2
Here, enrol_no → dept and dept → building_no. Hence, according to the axiom of
transitivity, enrol_no → building_no is a valid functional dependency. This is an
indirect functional dependency, hence called Transitive functional dependency.
18
BCNF stands for Boyce-Codd normal form and was made by R.F Boyce and E.F Codd
in 1974.A functional dependency is said to be in BCNF if these properties hold:
• It should already be in 3NF.
• For a functional dependency say P->Q, P should be a super key.
Q.6 Consider the relational database as given below and write down
expressions in relational algebra for the following queries.
Data_Master(data_id, item name, reorder level)
Data_Details (data_id, Supplier_id, Purchase_date, Qty, Utcost)
i) Select supplier id where purchase date is 4th December, 2022)
Ans-> π_Supplier_id (σ_Purchase_date='2022-12-04' (Data_Details))
ii) Select the minimum quantity sold.
Ans-> π_Qty ( Data_Details ⨝ ρ_MinQty(Qty) ( σ_Qty = ( SELECT MIN(Qty) FROM
Data_Details ) (Data_Details) ) )
iii) Select name of the item where supplier id is ‘S00001’
Ans-> π_item_name ( (σ_Supplier_id='S00001' (Data_Details)) ⨝ Data_Master )
Q.7 Consider the following two schedules. Check whether both of these schedules are
conflict-serializable or not. Explain.
S1: R1(X) R1(Y) R2(X) R2(Y) W2(Y) W1(X)
S2: R1(X) R2(X) R2(Y) W2(Y) R1(Y) W1(X)
Q.8 Given a set of FDs for the relation schema R (A,B,C,D,E). The FDs are {BC―>D,
AC―>BE, B―>E}. Explain and find out the highest normal form of R.
Q.9 Design a database for a college. Many students seek admission in the college. The
college has a number of departments and students can be enrolled to these
departments. The department also offers a number of courses to the students, each
with a different duration from the other. Each department has its H.O.D and many
teachers under him. The syllabus of each course is also defined. Teachers are
recruited by the college for teaching the said courses to the students. The teachers
may have different qualifications and experience. They may also teach different
subjects if required. Each student in the college has a unique ID. We need to store the
names of the students studying in the college, their residential address, date of birth.
We also need to store information about the college like the name, address, contact
number, reference ID, departments of the college, name of the H.O.D, number of
teachers and students in the department. Also, the courses offered by the
departments, the syllabus, the duration and the course ID. We can also store
information about the teachers like their qualification, experience, name and
subjects taught.
Draw ER Diagram for this case study.
Q.10 Explain three level architecture of DBMS.
• This framework is used to describe the structure of a specific database
system.
• The three schema architecture is also used to separate the user applications
and physical database.
• The three schema architecture contains three-levels. It breaks the database
down into three different categories.
19
Objectives of Three schema Architecture
The main objective of three level architecture is to enable multiple users to access
the same data with a personalized view while storing the underlying data only
once. Thus it separates the user's view from the physical structure of the database.
This separation is desirable for the following reasons:
o Different users need different views of the same data.
o All users should be able to access the same data according to their
requirements.
o Internal structure of the database should be unaffected by changes to
physical aspects of the storage.
1. Internal Level
o The internal level has an internal schema which describes the physical
storage structure of the database.
o The internal schema is also known as a physical schema.
o It uses the physical data model. It is used to define that how the data will be
stored in a block.
o The physical level is used to describe complex low-level data structures in
detail.
2. Conceptual Level
Q.11 Create a B+ tree ( of order-3) with the following keys 8, 5 , 1, 7, 3, 12, 9, 6 And now
delete 12, 5
Q.12 Explain the difference between Primary index & secondary index.
Example: If the block size is 4 KB (4096 bytes) and each record size is 512
bytes, then: BF=4096 / 512=8 records per block.
Block Anchor: A reference or a pointer to the first record stored in a block. Used to
locate records within a block or page quickly. It helps in efficient block access and
navigation during database operations. Example: In a B-tree, the block anchor helps
identify the range of keys present in that block, enabling faster searching.
Q.14 With proper example explain how recovery in a database system can be done using
LOG files when the following techniques are used
i) Immediate update technique ii) Deferred update technique
Q.15 Explain Entity Relationship Model. What do you mean by serializability of
transactions?
Q.16 Short note : (a) Data Models (b) Foreign key (c) Aggregate functions (d) Ordered
indexing and hashing (e) Wait/Die and Wound/Wait deadlock protocols (f)
Database languages (g) Armstrong’ axioms for FD’s.(h) Inner Join and Outer Join
(i) DBA(j) SQL joins(k) Keys in DBMS (l) Users in DBMS
Q.17 Explain about Selection, Projection, Rename, division and Cartesian product
operations in relational algebra? 7. Discuss about Domain Relational Calculus?
Write and explain a query in DRC to Find the names of sailors who have reserved
boat 103.
Q.18 Determine the closer of the following set of functional dependencies for a relational
scheme R(A,B,C,D) and FDs {AB → C, C → D, D → A}. List out the candidate keys of R.
21
Determine the closer of the following set of functional dependencies for a relational
scheme R(A,B,C,D) and FDs {AB → C, C → D, D → A}. List out the candidate keys of R.
Q.19 Explain about Aggregate operators in sql with examples? 2. Discuss correlated
nested queries? Explain about Selection, Projection, Rename, division and Cartesian
product operations in relational algebra?
Q.20 What is a Phantom deadlock? What is a checkpoint and when does
it occur?
Differentiate between Clustered and non-Clustered indexes.
Ans-> A phantom deadlock is a situation where a deadlock detection algorithm
incorrectly identifies a deadlock in the system, even though no actual deadlock
exists. This leads to unnecessary actions, like rolling back transactions or aborting
processes, which affects system performance.
Example:
1. System State at Time T1:
o Transaction T1 is holding Resource R1 and waiting for R2.
o Transaction T2 is holding Resource R2 and waiting for R1.
→ Looks like a deadlock is forming.
2. State Changes at Time T2:
o Before the deadlock detection algorithm runs, T1 releases R1,
allowing T2 to proceed.
o The system is no longer in a deadlock.
3. Phantom Detection:
o However, the deadlock detection algorithm, running on outdated
data, still assumes the deadlock exists and unnecessarily rolls back
one of the transactions.
Checkpoint: It is a mechanism where all the previous logs are removed from the
system and stored permanently in storage disk.
Types of Checkpoints
1. Automatic Checkpoint
2. Manual Checkpoint
1. Automatic Checkpoint: These checkpoints occur very frequently like every hour
or every day. These intervals are set by the database administrator. They are
generally used by heavy databases as they are frequently updated, and we can
recover the data easily in case of failure.
2. Manual Checkpoint: These are the checkpoints that are manually set by the
database administrator. Manual checkpoints are generally used for smaller
databases. They are updated very less frequently only when they are set by the
database administrator.
22