Dbms Question Paper With Answer
Dbms Question Paper With Answer
A
IT
C
EN
-R
24
20
n_
tio
lu
So
S-
BM
D
MODULE 1
A
● Query Processor: Converts user queries into low-level instructions for
IT
efficient access.
● Transaction Manager: Manages the execution of transactions while
C
ensuring ACID properties (Atomicity, Consistency, Isolation, and
EN
Durability).
● Concurrency Control Manager: Ensures transactions do not interfere
with each other.
-R
These modules interact to process user queries, ensure data consistency, manage
concurrent access, and store the data efficiently .
correctness (syntax, file names, etc.), and converts them into an internal
form.
lu
2. Application Programs
BM
A
executable query plans, and canned transactions with parameters.
IT
● It interacts with the system catalog and may update statistics related to the
database. It also works with the stored data manager, which handles I/O
C
operations between the disk and main memory.
EN
● Buffer management is handled either by the DBMS or the operating
system. The DBMS also includes concurrency control and
backup/recovery modules for transaction management.
-R
4. Client-Server Architecture
24
● Typically, the client program runs on a separate computer (client) that
20
accesses the database, which resides on a database server.
● In some cases, the client accesses a middle-tier application server, which
n_
the system is shared by many users. If dedicated, the DBMS may control
memory buffering of disk pages directly.
lu
● The DBMS interacts with the operating system when it needs to perform
S-
A
IT
C
EN
-R
24
20
n_
tio
lu
So
The three-schema architecture separates the user’s view from the physical
database and defines three levels:
D
external schema to the conceptual schema and then to the internal schema. This
ensures data independence at different levels.
A
IT
C
EN
-R
24
20
n_
Q1c. Explain the difference between logical and physical data independence.
tio
A
Project, Dependent is related to Employee
IT
● Constraints: Employee has one Department, and works on multiple
projects, Dependent weak entity relies on Employee.
C
EN
The diagram would look similar to the one in the textbook showing employees,
departments, and dependents.
-R
24
20
n_
tio
lu
So
S-
BM
D
Q2b. Define the following terms with examples using ER notations: Entity,
attribute, composite attribute, multivalued attribute, participation role.
A
Name, Last Name).
IT
● Multivalued Attribute: Attribute that can hold multiple values, e.g.,
Phone Numbers.
C
● Participation Role: Refers to an entity’s role in a relationship, e.g.,
EN
Employee works in Department
-R
MODULE 2
24
Q3a. Discuss update operations and constraint violations with examples.
20
Update operations include Insert, Delete, and Update. These can violate
n_
● The operations of the relational model are categorized into retrievals and
lu
updates.
So
2. Insert Operation
A
○ Inserting a tuple with an existing primary key value violates key
constraints and is rejected.
IT
○ Inserting a tuple with an invalid foreign key violates referential
C
integrity.
○ A valid insert operation satisfies all constraints.
EN
3. Delete Operation
-R
● Delete removes tuples from a relation, and it can only violate referential
integrity.
24
○ Referential integrity violation occurs if other tuples reference the
tuple being deleted. For example, deleting an EMPLOYEE tuple
20
could cause issues if other relations like WORKS_ON or
DEPENDENT reference it.
n_
4. Update Operation
S-
constraints:
○ Domain constraints if the new value is not of the correct type.
○ Key constraints if updating the primary key duplicates an existing
D
value.
○ Referential integrity if modifying a foreign key references a
non-existing tuple.
● Examples:
○ Updating an employee’s salary or department number is acceptable
as long as it doesn't violate any integrity constraints.
A
or set null.
IT
C
EN
Q3b. Relational algebra operators for select and project operations.
● Select (σ): Retrieves rows that satisfy a condition, e.g., σ(Salary >
-R
30000)(Employee).
● Project (π): Retrieves specific columns, e.g., π(Name, Salary)(Employee).
24
Q3c. Characteristics of relations that make them different from ordinary
data.
20
1. Tabular Structure (Relations are Tables)
n_
represents a tuple (or record), and each column represents an attribute (or
field).
lu
defines the permissible values the attribute can take. For example, a
domain for a "Date of Birth" column might only accept valid date values.
● Attributes must maintain atomicity, meaning every value in a relation
D
3. Uniqueness of Tuples
● In a relational model, each tuple must be unique. No two rows can have
identical values for all attributes. This is enforced by the primary key, a
unique identifier for each tuple.
● Primary keys ensure the integrity of the data and allow the database to
reference individual records precisely.
4. No Duplicates
A
5. Unordered Tuples and Attributes
IT
● Tuples (rows) in a relation are not ordered. Unlike arrays or lists in
C
programming, the order of tuples is irrelevant, and the DBMS does not
EN
enforce a particular order.
● Attributes (columns) are also unordered, meaning the left-to-right order of
columns does not affect the definition or behavior of the relation.
-R
6. Integrity Constraints
24
● Relations are subject to various integrity constraints that ensure the
20
correctness and consistency of the data:
○ Domain constraints: Values in each column must come from the
attribute's domain.
n_
○ Key constraints: The primary key must be unique for every tuple.
○ Referential integrity: A foreign key in one relation must reference
tio
7. Relational Operations
including:
○ Selection: Retrieving rows based on conditions.
BM
8. Data Independence
9. Set-Based Theory
A
different from ordered data structures in programming.
IT
10. Null Values
C
EN
● Relations can accommodate NULL values, which represent unknown,
missing, or inapplicable information. However, certain constraints, like
primary keys, may disallow NULL values.
-R
11. Normalization
24
● Relations can be normalized to reduce redundancy and improve data
20
integrity. Normalization organizes data into smaller, related relations to
eliminate anomalies during insertion, deletion, or update operations.
●
n_
tio
i)
D
A
IT
C
EN
-R
24
20
n_
ii)
tio
lu
So
S-
iii)
BM
D
iv)
A
IT
C
EN
b. Consider the following relational database schema and write the queries
-R
in relational algebra expressions:
EMP(Eno, Ename, Salary, Address, Phone, DNo)
DEPT(DNo, Dname, Dloc, MgrEno)
DEPENDENT(Eno, DepName, Relation, Dage) 24
20
1. List all the employees who reside in ‘Belagavi’.
2. List all the employees who earn between 30000 and 40000.
n_
3. List all the employees who work for the ‘Sales’ department.
4. List the employees who have at least one dependent.
tio
5. List the department names along with the names of the managers.
lu
So
S-
BM
D
A
IT
C
EN
-R
24
20
n_
tio
lu
So
S-
BM
D
MODULE 3
Module 3:
A
14.1.1 Clear Semantics
IT
● Definition: Relation attributes should have clear real-world meanings.
C
● Importance: A well-designed relation schema is easier to explain and
EN
interpret.
● Example: The EMPLOYEE schema clearly represents employee data,
-R
with attributes like name and department number, indicating an implicit
relationship with the DEPARTMENT schema.
24
● Guideline: Design schemas to ensure each relation corresponds to a single
entity or relationship to avoid semantic ambiguity.
20
14.1.2 Redundant Information and Update Anomalies
n_
● Anomalies:
○ Insertion Anomalies: Difficulty adding new data (e.g., a new
lu
A
IT
C
Q5b.Explain 1NF, 2NF, and 3NF with examples.
EN
● 1NF (First Normal Form): Ensures atomicity of values.
● 2NF (Second Normal Form): Ensures no partial dependency, every
-R
non-key attribute must depend on the whole primary key.
● 3NF (Third Normal Form): Ensures no transitive dependency, i.e.,
non-key attributes do not depend on other non-key attributes.
24
20
n_
tio
lu
So
S-
BM
D
A
IT
C
EN
-R
24
20
n_
tio
lu
So
S-
BM
D
A
IT
C
EN
-R
24
20
n_
tio
A
IT
C
EN
-R
24
20
n_
tio
lu
So
S-
BM
D
A
IT
C
EN
-R
24
20
n_
tio
lu
So
S-
BM
D
A
IT
C
EN
-R
24
20
n_
tio
6a). Discuss insertion, deletion, and modification anomalies. Why are they
considered bad? Illustrate with examples.
lu
anomalies. They are considered bad because they compromise the integrity of the
data and may result in inconsistencies or the loss of important information.
BM
1. Insertion Anomaly:
An insertion anomaly occurs when it is impossible to insert data into the table
D
If you want to add a new department (say "Finance") without assigning any
employee to it, you cannot insert it into this table unless you also provide some
A
employee information. This dependency creates an insertion anomaly, as you
can't insert department data without inserting employee data.
IT
C
EN
2. Deletion Anomaly:
A deletion anomaly occurs when deleting data about one entity inadvertently
-R
causes loss of data about another entity. This is common in non-normalized
tables where data is stored redundantly.
D e D e
101 John 10 HR
tio
If you delete the row for employee Susan, you also lose information about the
Finance department (DeptID 20), even though that department may still exist.
S-
BM
3. Modification Anomaly:
updated in multiple places. If you update it in one place and forget to update it
elsewhere, the database will have inconsistent data.
Human Resources.
A
Resources
IT
C
Why are these anomalies considered bad?
EN
● Data Redundancy: Storing the same information multiple times leads to
redundancy, which wastes storage space and makes the system harder to
-R
manage.
● Data Inconsistency: If the same information is stored in multiple places,
24
there’s a risk that it will become inconsistent over time due to modification
anomalies.
20
● Difficulty in Data Management: Anomalies make it harder to insert,
update, or delete records without affecting unrelated data. This increases
n_
Normalization as a Solution:
So
data.
D
(i) SQL provides various data types to define the type of data that can be stored
ID INT,
A
Name VARCHAR(50),
IT
Age INT
C
);
EN
●
-R
VARCHAR(size): Stores variable-length string data (e.g., John, Database).
Name VARCHAR(100)
n_
);
tio
●
lu
ProductID INT,
BM
Price FLOAT
);
D
OrderID INT,
OrderDate DATE
);
A
BOOLEAN: Stores true/false values.
IT
CREATE TABLE Flags (
C
FlagID INT,
EN
IsActive BOOLEAN
-R
);
(ii)
24
20
SQL provides the LIKE operator for pattern matching using wildcards, and it is
n_
commonly used to search for substrings in string data. The two main wildcards
used with LIKE are:
tio
Examples:
SELECT Name
FROM Students
D
● This query retrieves all names that begin with the letter 'A'.
SELECT Name
FROM Employees
A
Find names where the second letter is 'a':
IT
SELECT Name
C
FROM Employees
EN
WHERE Name LIKE '_a%';
-R
●
FROM Employees
n_
MODULE 4
So
Write the following queries in SQL. No duplicates should be printed in any of the
answers.
(i) Find the names of all Juniors (level = JR) who are enrolled in a class
taught by I. Teach.
A
AND S.level = 'JR'
IT
AND F.fname = 'I. Teach';
C
EN
This query joins the Student, Enrolled, Class, and Faculty tables to find the
students who are at the junior level and enrolled in a class taught by a specific
faculty member.
-R
24
(ii) Find the names of all classes that either meet in room R128 or have five
20
or more students enrolled.
n_
SELECT C.Cname
So
This query uses a UNION to combine the results of two conditions: classes
meeting in room R128 or classes with five or more students enrolled.
D
(iii) For all levels except JR, print the level and the average age of students
for that level.
This query calculates the average age of students for each level except for
A
juniors.
IT
C
EN
(iv) For each faculty member that has taught classes only in room R128,
print the faculty member’s name and the total number of classes he or she
has taught.
-R
SELECT F.fname, COUNT(C.Cname) AS Total_Classes
FROM Faculty F, Class C 24
20
WHERE F.fid = C.fid
AND C.room = 'R128'
n_
GROUP BY F.fname
HAVING COUNT(DISTINCT C.room) = 1;
tio
This query finds faculty members who have only taught classes in room R128
lu
and returns their name and the total number of classes they have taught.
So
S-
SELECT S.Sname
FROM Student S
D
This query retrieves the names of students who are not enrolled in any class by
using a NOT IN subquery.
Example:
A
IT
SELECT Sname, age
C
FROM Student S
EN
WHERE age > (SELECT AVG(age) FROM Student WHERE Branch =
S.Branch);
-R
Here, the inner query refers to the outer query's Branch, and for each student, the
average age of students in that branch is calculated.
24
20
● Nested Query: A nested query is a query within another query, where the
inner query is executed once and its result is passed to the outer query.
n_
Example:
tio
FROM Student
WHERE age > (SELECT AVG(age) FROM Student);
So
S-
Here, the inner query calculates the average age once, and the result is used to
compare against the age of each student.
BM
The ACID properties ensure that database transactions are processed reliably.
They are:
A
another. Intermediate results of a transaction are not visible to other
transactions until the transaction is committed.
IT
Example: If two users try to update the same account balance
C
simultaneously, isolation ensures that both transactions are handled in a
serializable manner.
EN
4. Durability: Ensures that once a transaction is committed, it remains so,
even in the event of a system crash. The results of the transaction are
-R
permanently stored in the database.
Example: Once a bank transfer transaction is committed, it is reflected in
the database even if the system crashes immediately afterward.
24
20
n_
Views in SQL are virtual tables based on the result of an SQL query. They do not
store data themselves but provide a way to look at and manipulate the result of a
lu
Example:
S-
FROM Employees
WHERE Salary > 50000;
D
Benefits of Views:
A
a view instead of the base table.
IT
3. Data Abstraction: Views provide an abstraction layer over the database
schema.
C
EN
Q8b. In SQL, write the usage of GROUP BY and HAVING clauses with
-R
suitable examples.
24
● GROUP BY: The GROUP BY clause is used to group rows that have the
same values in specified columns. It is often used with aggregate functions
20
(COUNT, SUM, AVG, etc.).
● HAVING: The HAVING clause is used to filter the groups based on certain
conditions, similar to WHERE but for groups.
n_
Example:
tio
lu
FROM Employees
S-
GROUP BY DeptID
BM
In this query, we count the number of employees in each department and return
Q8c. Discuss the types of problems that may encounter with transactions
that run concurrently.
When transactions run concurrently, several problems can arise, affecting the
A
consistency and isolation of the database. These problems include:
IT
1. Lost Update: Occurs when two transactions simultaneously update the
C
same data. The update of one transaction may overwrite the other, leading
EN
to lost data.
Example:
○ Transaction A reads a value of 100 from the database.
-R
○ Transaction B also reads the value 100, increments it to 110, and
writes it back.
24
○ Transaction A increments its original value (100) to 105 and writes
it back, thus "losing" the update made by Transaction B.
20
2. Dirty Read: Occurs when a transaction reads data that has been written by
another transaction but not yet committed. If the second transaction is
n_
concurrent transactions.
Example:
BM
4. Phantom Read: Occurs when a transaction reads a set of rows that satisfy a
certain condition, but when it repeats the query, new rows satisfying the
condition appear due to insertions by other transactions.
Example:
○ Transaction A reads all rows where Salary > 50000.
○ Transaction B inserts a new row with Salary = 60000.
MODULE 5
A
a. What is the two-phase locking protocol? How does it guarantee
IT
serializability?
C
The two-phase locking (2PL) protocol is a concurrency control method used to
EN
ensure serializability of database transactions. A transaction is said to follow the
two-phase locking protocol if all locking operations (acquiring locks) precede the
first unlock operation (releasing locks). This divides the transaction into two
-R
phases:
24
● Growing Phase: The transaction acquires all required locks and cannot
release any lock.
20
● Shrinking Phase: The transaction releases the locks and cannot acquire
any more.
n_
By enforcing that no new locks can be acquired after the release of any lock, 2PL
guarantees that the transactions will be executed in a serializable manner, i.e., the
tio
A
IT
C
EN
-R
24
20
n_
tio
lu
So
S-
BM
D
A
a younger transaction, the older transaction waits. If a younger transaction
IT
requests a lock held by an older transaction, the younger transaction is aborted
C
("dies") and restarted later with the same timestamp.
Wound-Wait Protocol: In this scheme, if an older transaction requests a lock held
EN
by a younger transaction, the younger transaction is aborted ("wounded") and
restarted later. However, if a younger transaction requests a lock held by an older
-R
transaction, the younger transaction waits
Document-Based NoSQL:
{
D
"_id": 1,
"name": "John",
"age": 30,
"email": "[email protected]"
Key-Value Store:
A
{
IT
"John": {"age": 30, "email": "[email protected]"}
C
}
EN
-R
Column-Based Store:
|1 | John | 30 | [email protected] |
n_
tio
Graph-Based (Neo4j):
lu
(John)-[:FRIEND_OF]->(Jane)
So
S-
BM
A
IT
C
EN
-R
24
20
n_
tio
lu
So
The compatibility table of the three intention locks, and the actual shared and
S-
5. A transaction T can lock a node only if it has not unlocked any node (to
enforce the 2PL protocol).
A
IT
b. Discuss the following MongoDB CRUD operations with their formats:
Insert: Adds new documents into a collection using the command:
C
EN
db.collection.insert(document)
-R
Delete: Removes documents from a collection using the command:
db.collection.remove(query) 24
20
n_
db.collection.find(query)
lu
So
Documents can be created and inserted into their collections using the insert
BM
A
c. Briefly discuss about Neo4j data model.
IT
The Neo4j data model is based on a graph structure where:
C
● Nodes: Represent entities such as people, places, or objects, and can have
EN
properties.
● Relationships: Represent connections between nodes and are directed.
They can also have properties.
-R
● Properties: Key-value pairs associated with nodes or relationships.
● Labels: Group nodes into sets for querying. Nodes can have zero or
multiple labels. 24
20
The graph-based model is flexible and well-suited for complex queries involving
relationships, as seen in social networks, fraud detection, and recommendation
n_
systems
tio
● Labels categorize nodes. For example, in Figure 24.4(a), the nodes are
lu
LOCATION.
● Properties are attributes stored in curly brackets {...}. Nodes can have
S-
and EER).
3. Paths
A
IT
4. Optional Schema
C
● Neo4j can function without a predefined schema. However, version 2.0
EN
introduced schema-related functions like indexes and constraints. For
instance, a key constraint can ensure that a certain property (e.g., EmpId)
is unique within a label (e.g., EMPLOYEE).
-R
5. Indexing and Node Identifiers