Database Management System-Question Bank-2 Answer Key
Database Management System-Question Bank-2 Answer Key
Question Bank-2
Compare DDL (Data Definition Language) and DML (Data Manipulation Language) in SQL.
DDL (Data Definition Language): Includes commands like CREATE, ALTER, and DROP that define
1
or modify the structure of database objects (tables, schemas, etc.).
DML (Data Manipulation Language): Includes commands like SELECT, INSERT, UPDATE, and
DELETE that allow users to manipulate and query data within the tables.
Explain the importance of Fifth Normal Form (5NF).
Fifth Normal Form (5NF) deals with join dependency and ensures that a relation is free from
redundancy due to multiple relationships between attributes. A table is in 5NF if it cannot be
decomposed into smaller tables without losing information.
Importance:
Eliminates Redundancy: 5NF ensures that data is stored in a way that minimizes
2
redundancy, especially in complex relationships.
Prevents Update Anomalies: By ensuring that each piece of information is stored in
only one place, it prevents issues like inconsistent updates across multiple places in the
database.
In practice, 5NF is often considered in systems where there are highly complex relationships
involving multiple attributes, though it is less commonly used in most everyday database
designs.
Explain the concept of a transaction in database management systems.
Deadlock: A situation in which two or more transactions are waiting for each other to
4 release resources, causing all of them to be stuck indefinitely without making progress.
Livelock: A situation in which transactions continuously change states in response to
each other but never make any actual progress, often by repeatedly retrying an
operation.
How does a transaction move from the "Active" state to the "Committed" state?
A transaction moves from the "Active" state to the "Committed" state after successfully
5
completing all its operations, meeting all integrity constraints, and receiving a commit
command. Once committed, the transaction's changes are permanently applied to the database
and cannot be undone.
Identify the differences between functional dependency, transitive dependency, and multivalued
dependency with examples.
6
Multivalued Dependency
1. Functional Dependency (FD):
o Definition: A functional dependency exists when one attribute (or set of
attributes) in a relation uniquely determines another attribute.
o Notation: A → B means that attribute A uniquely determines attribute B.
o Example:
Student (StudentID, StudentName, Course)
Here, StudentID → StudentName indicates that a StudentID uniquely
determines the StudentName.
2. Transitive Dependency:
o Definition: A transitive dependency occurs when one attribute depends on
another, which in turn depends on a third attribute. It happens if A → B and B
→ C, then A → C.
o Example:
Employee (EmpID, EmpName, DeptID, DeptName)
If EmpID → DeptID and DeptID → DeptName, then EmpID →
DeptName is a transitive dependency.
3. Multivalued Dependency (MVD):
o Definition: A multivalued dependency exists when one attribute determines a
set of values for another attribute, independent of other attributes.
o Notation: A ↠ B means that for each value of A, there is a set of possible values
for B.
o Example:
Student (StudentID, Hobby, Language)
If a student has multiple hobbies and languages, then StudentID ↠
Hobby and StudentID ↠ Language indicate that StudentID determines
a set of hobbies and a set of languages independently.
Explain how Fourth Normal Form (4NF) handles multivalued dependencies and provide an
example.
Fourth Normal Form (4NF): A relation is in 4NF if it is in Boyce-Codd Normal Form (BCNF)
and has no multivalued dependencies.
Handling MVDs in 4NF: In 4NF, multivalued dependencies are eliminated by
decomposing the relation. If an MVD exists between two sets of attributes, they should
be separated into different relations to eliminate redundancy.
Example:
7
Student (StudentID, Hobby, Language)
o A student can have multiple hobbies and multiple languages. If the hobbies and
languages are independent of each other, a multivalued dependency StudentID
↠ Hobby and StudentID ↠ Language may exist.
To convert the relation to 4NF:
o Decompose into two relations:
StudentHobby (StudentID, Hobby)
StudentLanguage (StudentID, Language)
This decomposition eliminates the multivalued dependencies and ensures the relation is in 4NF.
Explain the key differences between 3NF and BCNF and discuss scenarios where BCNF is
preferred over 3NF.
Explain the differences between 2NF, 3NF, and BCNF with suitable examples.
1. Second Normal Form (2NF): A table is in 2NF if it is in 1NF (no repeating groups or arrays),
and every non-prime attribute is fully dependent on the entire primary key (i.e., no partial
dependency).
Partial Dependency occurs when a non-prime attribute is dependent on only part of a composite
primary key.
Example of 2NF: Consider a table with a composite primary key (Student_ID, Course_ID):
diff
Copy
Student_Course
------------------------------
Student_ID | Course_ID | Instructor
------------------------------
1 | Math | Dr. Smith
10 1 | Science | Dr. Johnson
2 | Math | Dr. Smith
Here, Instructor is partially dependent on Course_ID (not the full primary key (Student_ID,
Course_ID)), so it violates 2NF. To bring it into 2NF, the table is divided into two tables:
Student_Course (Student_ID, Course_ID)
Course_Instructor (Course_ID, Instructor)
2. Third Normal Form (3NF): A table is in 3NF if it is in 2NF and every non-prime attribute
is transitively dependent only on the primary key. This means there should be no transitive
dependency, i.e., a non-prime attribute shouldn't depend on another non-prime attribute.
Transitive Dependency occurs when a non-prime attribute depends on another non-prime
attribute.
Example of 3NF: Consider the following table, where Student_ID is the primary key:
pgsql
Copy
Student_Info
-----------------------------------
Student_ID | Name | Department | Dept_Head
-----------------------------------
1 | Alice | CS | Dr. Lee
2 | Bob | IT | Dr. Smith
3 | Charlie| CS | Dr. Lee
Here, Dept_Head is transitively dependent on Department, since Dept_Head depends on
Department, which in turn depends on Student_ID.
To bring it into 3NF, we create two tables:
Student_Info (Student_ID, Name, Department)
Department_Info (Department, Dept_Head)
3. Boyce-Codd Normal Form (BCNF): A table is in BCNF if it is in 3NF and for every non-
trivial functional dependency, the determinant is a superkey. In simpler terms, BCNF requires
that for every functional dependency, the attribute on the left side of the dependency must be a
candidate key.
Example of BCNF: Consider the following table, where Student_ID and Course_ID together
form the primary key:
markdown
Copy
Student_Course_Info
---------------------------------
Student_ID | Course_ID | Instructor
---------------------------------
1 | Math | Dr. Smith
1 | Science | Dr. Johnson
2 | Math | Dr. Smith
Here, Instructor is dependent on Course_ID, not on the whole primary key (Student_ID,
Course_ID). This violates BCNF because Course_ID is not a superkey, even though it determines
Instructor.
To bring this table into BCNF, we would split the table into two:
Student_Course (Student_ID, Course_ID)
Course_Instructor (Course_ID, Instructor)
Summary of Differences:
Normal
Key Condition Example
Form
Eliminates partial dependency (non-prime Instructor dependent only on
2NF
attributes depend on the entire composite key). Course_ID needs splitting.
Eliminates transitive dependency (non-prime Dept_Head dependent on Department
3NF
attributes depend on other non-prime attributes). requires splitting.
Ensures that for every functional dependency, the Instructor dependent on Course_ID but
BCNF
determinant is a superkey. Course_ID isn't a superkey.
In conclusion:
2NF addresses partial dependency.
3NF eliminates transitive dependency.
BCNF strengthens the 3NF by eliminating situations where a non-superkey attribute
determines another attribute.
Explain the significance of Fifth Normal Form (5NF) and provide a real-world case where PJNF
is essential for database design.
Deadlock in transaction management occurs when two or more transactions are unable to proceed
because each is waiting for the other to release resources. This creates a situation where no
transaction can make progress, potentially leading to system inefficiency and reduced
performance. Deadlock detection and prevention are essential to ensure that the database
management system (DBMS) operates smoothly.
Deadlock Detection:
Definition: Deadlock detection involves identifying situations where transactions are
stuck in a circular wait, meaning that no progress can be made.
Importance:
1. Prevents System Freezing: Detecting deadlocks ensures that the system does
not become stuck, which could freeze operations and impact user experience.
2. Allows for Recovery: Once deadlocks are detected, the system can resolve the
issue by aborting one or more of the transactions involved, freeing up the
12
resources.
3. Enhances Resource Allocation: Deadlock detection allows for the efficient use
of resources by resolving conflicts when detected.
Deadlock Prevention:
Definition: Deadlock prevention involves taking steps to ensure that deadlocks do not
occur in the first place by controlling how resources are allocated.
Importance:
1. Improves Transaction Flow: By preventing deadlocks, transactions can
proceed without unnecessary delays, ensuring smooth operations.
2. Optimizes Performance: Preventing deadlocks reduces the need for complex
recovery mechanisms and allows better management of system resources.
3. Avoids Wasted Resources: Prevention avoids the waste of resources that could
occur when transactions are in a deadlock state.
Both deadlock detection and prevention are crucial for maintaining system efficiency, reducing
downtime, and ensuring the integrity of transaction management in a database system.
Identify and describe the ACID properties of a transaction with examples.
The ACID properties (Atomicity, Consistency, Isolation, and Durability) ensure reliable and
correct execution of transactions in a database management system (DBMS). Each property
13 addresses specific aspects of transaction reliability.
1. Atomicity:
o Definition: Atomicity ensures that a transaction is treated as a single unit of
work. Either all operations in the transaction are completed successfully, or none
of them are applied (i.e., a transaction is "all or nothing").
o Example: Consider a banking transfer where $100 is moved from Account A to
Account B. If the system fails midway, the entire transaction is rolled back, and
no money is transferred, maintaining atomicity.
2. Consistency:
o Definition: Consistency ensures that a transaction transforms the database from
one valid state to another. After a transaction, the database must satisfy all
predefined rules, constraints, and relationships (e.g., no violation of foreign keys
or data integrity).
o Example: In the same banking system, a transaction should not leave Account
A with a negative balance. If the transaction would result in such an
inconsistency, the transaction will not be completed.
3. Isolation:
o Definition: Isolation ensures that transactions are executed independently of one
another, even if they are executed concurrently. The intermediate states of
transactions are not visible to other transactions until they are fully completed.
o Example: If two users are trying to update the same bank account at the same
time, the isolation property ensures that one transaction is completed before the
other begins, preventing inconsistencies like double withdrawals.
4. Durability:
o Definition: Durability ensures that once a transaction has been committed, it is
permanent, even in the case of system failures (e.g., power loss or crash). The
changes made by the transaction are saved and cannot be lost.
o Example: If a user deposits $500 into their bank account and the system crashes
immediately afterward, once the system is restored, the transaction will be
reflected in the account balance.
Summary:
Atomicity ensures that all parts of a transaction are completed, or none are applied.
Consistency ensures the database moves from one valid state to another.
Isolation ensures that transactions are independent of each other.
Durability guarantees that committed transactions are permanent, even after a system
failure.
These ACID properties are essential for maintaining the integrity, reliability, and correctness of
transactions in a database system.
Identify different transaction states and explain the transitions between them with a state
diagram.?
A transaction in a database management system (DBMS) undergoes various states during its
execution. These states represent different stages in the lifecycle of a transaction. Understanding
the states and transitions is crucial for managing transactions effectively, ensuring they are
executed correctly, and handling failures.
Transaction States:
There are several key states that a transaction can be in:
1. New:
o Definition: The transaction is created but has not yet started executing.
o Transition: The transaction moves from the New state to the Active state once
it begins executing.
14
2. Active:
o Definition: The transaction is actively executing and making changes to the
database.
o Transition: The transaction may either commit (successfully complete) or abort
(fail and roll back) from this state.
3. Partially Committed:
o Definition: The transaction has executed all its operations and reached the point
where it is about to be committed, but it has not yet been permanently saved to
the database.
o Transition: This state occurs if the transaction finishes execution and is waiting
to be committed (i.e., all the operations are successful up to that point).
4. Committed:
o Definition: The transaction has successfully completed and all changes have
been permanently saved to the database.
o Transition: Once committed, the transaction state becomes final, and no further
action can be taken. The transaction is considered successfully executed.
5. Aborted:
o Definition: The transaction has failed during execution or explicitly requested to
be rolled back. All changes made by the transaction are undone, and the
transaction is terminated.
o Transition: If a transaction is in the Active state and encounters an error or a
deadlock, it may transition to Aborted. Alternatively, if the transaction is
explicitly rolled back, it enters the Aborted state.
6. Terminated:
o Definition: The transaction has been successfully committed or aborted, and no
further actions will be taken. This state signifies that the transaction has
completed its life cycle.
o Transition: Once the transaction is either Committed or Aborted, it enters the
Terminated state, which represents the end of the transaction's lifecycle.
State Transitions:
The transitions between these states are governed by the actions of the system and the transaction
itself.
1. New → Active: The transaction starts executing.
2. Active → Partially Committed: The transaction successfully finishes execution and is
ready to be committed.
3. Partially Committed → Committed: The transaction is permanently saved to the
database.
4. Active → Aborted: The transaction encounters an error, failure, or deadlock, and is
rolled back.
5. Aborted → Terminated: After a transaction is aborted, it ends, and no further action is
possible.
6. Committed → Terminated: After the transaction is committed, it is considered finished,
and no further changes will occur.
State Diagram:
Here is a state diagram representing the lifecycle of a transaction:
pgsql
Copy
+------------+ start +------------+ commit +------------+
| New |---------------->| Active |------------------->| Partially |
| | | | | Committed |
+------------+ +------------+ +------------+
| |
| |
| |
abort | | commit
v v
+------------+ +------------+
| Aborted |<---------| Committed |
+------------+ +------------+
| |
| |
v v
+------------+ +------------+
| Terminated |<-------->| Terminated |
+------------+ +------------+
New → Active: This transition occurs when a transaction is initiated and begins its
execution.
Active → Partially Committed: This transition takes place after all the operations of a
transaction have been executed successfully and the system is ready to commit the
changes.
Active → Aborted: If a transaction encounters an issue, such as a deadlock or an error,
it is aborted and all changes are undone.
Partially Committed → Committed: After successful execution, the transaction
reaches this state when it is saved permanently to the database.
Active → Aborted: If an error occurs during execution or the transaction is explicitly
rolled back, it transitions to the Aborted state.
Aborted → Terminated: Once a transaction has been aborted, it is considered
terminated.
Committed → Terminated: Once the transaction is successfully committed, it is
considered complete and enters the Terminated state.
Importance of Transaction States:
1. Managing Errors: By having different states, a DBMS can effectively handle failures
and recover by rolling back transactions from any state before Commit.
2. Concurrency Control: The states allow the system to manage concurrent transactions,
ensuring that transactions can execute without conflicting with one another.
3. Consistency: Each state ensures that the database maintains its integrity by only
committing changes after confirming that the transaction has successfully completed.