10. DBMS
10. DBMS
Basic Concepts
🔹 DBMS Architecture
● Single-Tier Architecture: All tasks on one machine.
● Three-Tier Architecture:
🔹 ER Model (Entity-Relationship)
● Entity: Real-world object (e.g., Student, Book).
● Types of Attributes:
● Types of Relationships:
● Keys:
📘 2. Relational Models
🔹 Relational Model
● Data is stored in tables (relations) consisting of rows (tuples) and columns
(attributes).
🔹 Relational Algebra
● Procedural query language to retrieve data.
● Operators:
○ Rename (ρ)
○ Join (⨝)
🔹 Constraints in RDBMS
● Primary Key: Uniquely identifies each tuple.
🔹 Views
● Virtual table derived from base tables.
Created using:
sql
Copy code
CREATE VIEW view_name AS
SELECT column1, column2 FROM table WHERE condition;
●
🔹 Updates in RDBMS
● UPDATE table SET column=value WHERE condition;
● Security:
○ Access controls using GRANT and REVOKE.
● Trivial FD: B ⊆ A
● Non-Trivial FD: B ⊄ A
🔹 Normalization
Process of removing redundancy and anomalies.
● Ensures:
○ R = R1 ⨝ R2
🔸 Primary Index:
● Based on the primary key of the table.
🔸 Secondary Index:
● Index on non-primary key attributes.
🔸 Clustered Index:
● Data is physically sorted according to the indexed column.
🔸 Non-clustered Index:
● Index structure is separate from data storage.
🔹 B-Tree
● Balanced multi-level index tree
● Maintains sorted data and allows search, sequential access, insertions, and deletions
in O(log n) time.
Properties:
● Height-balanced
● Internal nodes store keys and child pointers.
🔹 B+ Tree
● An extension of B-tree used in DBMS for efficient range queries.
Advantages:
📘 2. Transaction Management
🔹 Transaction
● A transaction is a sequence of operations treated as a single logical unit of work.
● ACID Properties:
Recoverable Schedule:
● A schedule where a transaction commits only after all transactions from which it has
read data have committed.
Cascadeless Schedule:
📘 3. Concurrency Control
Concurrency control manages simultaneous execution of transactions to avoid:
● Lost updates
● Temporary inconsistency
🔹 Types of Locks
● Shared Lock (S): For reading data.
🔹 Deadlock
Occurs when two or more transactions wait indefinitely for each other’s resources.
Deadlock Prevention:
● Wait-Die
● Wound-Wait
Deadlock Detection:
📘 4. Recovery Techniques
Used to bring the database to a consistent state after failures.
🔹 Shadow Paging
● Maintains two page tables: current and shadow.
Pros:
● Space overhead
1. DBMS Architecture Which layer of the DBMS architecture is responsible for
handling user requests and translating them into operations on the physical
database? a) External Schema b) Conceptual Schema c) Internal Schema d) Data
Definition Language (DDL)
Answer: c) Internal Schema
2. The three-schema architecture provides data independence. Which type of data
independence allows changes in the conceptual schema without affecting external
schemas? a) Physical Data Independence b) Logical Data Independence c) View
Data Independence d) Instance Data Independence
Answer: b) Logical Data Independence
3. Which component of a DBMS is responsible for creating and maintaining the data
dictionary? a) Query Processor b) Storage Manager c) DDL Interpreter d)
Transaction Manager
Answer: c) DDL Interpreter
5. The overall design of the database is called the: a) Schema b) Instance c) Tuple d)
Attribute
Answer: a) Schema
6. ER Model In an ER model, a "student" can be an entity, and "roll number" can be its:
a) Relationship b) Attribute c) Weak Entity d) Primary Key (more specific, but attribute
is generally correct for ER)
Answer: b) Attribute
11.An attribute that can have multiple values for a single entity instance is called a: a)
Simple attribute b) Composite attribute c) Multivalued attribute d) Derived attribute
Answer: c) Multivalued attribute
12.A derived attribute is an attribute whose value: a) Is stored directly in the database.
b) Is computed from other attributes. c) Has multiple values. d) Is part of a composite
attribute.
Answer: b) Is computed from other attributes.
16.Relational Model Constraints Which constraint ensures that no primary key value
can be NULL? a) Referential Integrity b) Entity Integrity c) Domain Constraint d) Key
Constraint
Answer: b) Entity Integrity
17.A foreign key is used to enforce which type of integrity constraint? a) Entity Integrity
b) Domain Constraint c) Referential Integrity d) Not Null Constraint
Answer: c) Referential Integrity
19.A candidate key is a superkey for which: a) All attributes are NULL. b) All attributes
are foreign keys. c) No proper subset of its attributes is also a superkey. d) It refers to
another table.
Answer: c) No proper subset of its attributes is also a superkey.
20.Relational Algebra Which relational algebra operation combines rows from two
relations? a) SELECT b) PROJECT c) UNION d) JOIN
Answer: c) UNION
21.The relational algebra operation that removes duplicate tuples and selects specific
columns is: a) SELECT b) PROJECT c) RENAME d) CARTESIAN PRODUCT
Answer: b) PROJECT
22.Which relational algebra operation is used to select tuples that satisfy a given
predicate? a) σ (Select) b) π (Project) c) ∪ (Union) d) × (Cartesian Product)
Answer: a) σ (Select)
23.The result of a JOIN operation between two relations R1and R2contains: a) Only
common attributes. b) All attributes from R1and R2. c) Attributes from R1and R2
based on a join condition. d) Only unique attributes.
Answer: c) Attributes from R1and R2based on a join condition.
25.SQL: Queries, Updates, Views, Integrity, Security Which SQL command is used to
retrieve data from a database? a) INSERT b) UPDATE c) DELETE d) SELECT
Answer: d) SELECT
26.Which clause is used with the SELECT statement to filter records based on a
specified condition? a) GROUP BY b) ORDER BY c) WHERE d) HAVING
Answer: c) WHERE
27.Which SQL command is used to add new rows to a table? a) ALTER TABLE b)
UPDATE c) INSERT INTO d) ADD ROW
Answer: c) INSERT INTO
28.To change existing data in a table, you use the SQL command: a) CREATE TABLE b)
UPDATE c) MODIFY d) ALTER
Answer: b) UPDATE
29.A virtual table based on the result-set of an SQL statement is called a: a) Index b)
View c) Trigger d) Stored Procedure
Answer: b) View
30.Which SQL statement is used to remove a view from the database? a) DELETE
VIEW b) REMOVE VIEW c) DROP VIEW d) ALTER VIEW
Answer: c) DROP VIEW
31.To grant specific privileges to a user, which SQL command is used? a) GRANT b)
ADD USER c) SET PERMISSION d) ALLOW
Answer: a) GRANT
32.What is the purpose of the REVOKE command in SQL? a) To create a new user
account. b) To remove a user from the database. c) To remove privileges from a user.
d) To refresh the database schema.
Answer: c) To remove privileges from a user.
33.Which of the following ensures that data remains consistent and correct in a
database? a) Query Optimization b) Data Redundancy c) Data Integrity d) Data
Definition
Answer: c) Data Integrity
34.A CHECK constraint in SQL is used to: a) Ensure uniqueness of values. b) Enforce
referential integrity. c) Restrict the values that can be placed in a column. d)
Automatically generate unique identifiers.
Answer: c) Restrict the values that can be placed in a column.
35.The ON DELETE CASCADE option in a foreign key constraint ensures that: a) If a row
in the parent table is deleted, corresponding rows in the child table are also deleted.
b) If a row in the parent table is deleted, corresponding rows in the child table are set
to NULL. c) Deletion in the parent table is prevented if there are matching rows in the
child table. d) A log of deleted rows is maintained.
Answer: a) If a row in the parent table is deleted, corresponding rows in the
child table are also deleted.
38.A relation is in 2NF if it is in 1NF and: a) Every non-key attribute is fully functionally
dependent on the primary key. b) It has no transitive dependencies. c) It has no
multivalued dependencies. d) It has only one candidate key.
Answer: a) Every non-key attribute is fully functionally dependent on the
primary key.
40.BCNF (Boyce-Codd Normal Form) is a stronger form of: a) 1NF b) 2NF c) 3NF d)
4NF
Answer: c) 3NF
45.Which normal form deals with multivalued dependencies? a) 1NF b) 2NF c) 3NF d)
4NF
Answer: d) 4NF
47.In a clustered index, the physical order of the data rows on disk: a) Is random. b) Is
determined by the order of the index key. c) Is independent of the index. d) Is only
applicable to views.
Answer: b) Is determined by the order of the index key.
48.A non-clustered index: a) Stores the actual data rows at the leaf level. b) Stores
pointers to the actual data rows at the leaf level. c) Can only be created on a primary
key. d) Allows only one per table.
Answer: b) Stores pointers to the actual data rows at the leaf level.
49.B-Tree - B+ Tree In a B-tree, data pointers can exist at: a) Only leaf nodes. b) Only
internal nodes. c) Both leaf and internal nodes. d) Only the root node.
Answer: c) Both leaf and internal nodes.
50.The primary advantage of a B+ Tree over a B-Tree for database indexing is: a)
Faster insertion and deletion. b) Better sequential access performance. c) Reduced
memory usage. d) Support for non-key searches.
Answer: b) Better sequential access performance.
51.In a B+ Tree, all data pointers are stored at the: a) Root node. b) Internal nodes. c)
Leaf nodes. d) Any node randomly.
Answer: c) Leaf nodes.
52.The leaf nodes of a B+ Tree are typically linked together: a) To form a hash table. b)
To facilitate efficient range queries. c) To create a circular list. d) To support random
access only.
Answer: b) To facilitate efficient range queries.
53.What is the fanout (order) of a B-tree or B+ tree? a) The number of data records. b)
The maximum number of children a node can have. c) The height of the tree. d) The
number of unique keys.
Answer: b) The maximum number of children a node can have.
54.If a B+ tree has a height of h and a fanout of m, the maximum number of disk I/Os to
retrieve a record is approximately: a) m b) h c) m×h d) logmN (where N is number of
records)
Answer: b) h
55.Which type of index is best suited for columns that have a small number of distinct
values (e.g., gender, true/false)? a) Clustered Index b) Unique Index c) Hash Index d)
Bitmap Index
Answer: d) Bitmap Index
58.A schedule is considered serializable if: a) Its result is equivalent to the result of
some serial schedule. b) All transactions commit. c) No deadlocks occur. d) All
transactions are executed concurrently.
Answer: a) Its result is equivalent to the result of some serial schedule.
59.A schedule where transactions are executed one after another without any
interleaving is called a: a) Concurrent schedule b) Serializable schedule c) Serial
schedule d) Recoverable schedule
Answer: c) Serial schedule
60.Which type of schedule ensures that if a transaction Tjreads a data item written by
Ti, then Timust commit before Tjcommits? a) Serial schedule b) Conflict serializable
schedule c) Recoverable schedule d) Strict schedule
Answer: c) Recoverable schedule
61.A schedule is conflict serializable if: a) It can be transformed into a serial schedule
by swapping non-conflicting operations. b) It can be transformed into a serial
schedule by swapping any operations. c) It involves only read operations. d) It has no
conflicting operations.
Answer: a) It can be transformed into a serial schedule by swapping
non-conflicting operations.
62.Two operations conflict if they: a) Belong to the same transaction. b) Access the
same data item, and at least one of them is a write operation. c) Are both read
operations on the same data item. d) Are executed by different users.
Answer: b) Access the same data item, and at least one of them is a write
operation.
65.Types of Locks A transaction holds a ________ lock on a data item X if it can read
X but no other transaction can write X. a) Exclusive (X) b) Shared (S) c) Intent (I) d)
Update (U)
Answer: b) Shared (S)
66.If a transaction holds an exclusive lock on data item X, what can other transactions
do with X? a) Read X. b) Write X. c) Both read and write X. d) Neither read nor write
X.
Answer: d) Neither read nor write X.
68.The two phases of 2PL are: a) Read phase and Write phase. b) Growing phase and
Shrinking phase. c) Acquire phase and Release phase. d) Commit phase and Abort
phase.
Answer: b) Growing phase and Shrinking phase.
69.In the shrinking phase of 2PL, a transaction: a) Can acquire new locks. b) Can
release existing locks. c) Can acquire new locks and release existing locks. d)
Cannot perform any operations.
Answer: b) Can release existing locks.
73.The "wait-die" and "wound-wait" schemes are used for: a) Deadlock prevention. b)
Deadlock detection. c) Deadlock recovery. d) Ensuring serializability.
Answer: a) Deadlock prevention.
74.If a system uses deadlock detection, what typically happens when a deadlock is
detected? a) The system reboots. b) One or more transactions are aborted
(victimized) to break the cycle. c) All transactions are committed. d) Locks are
automatically released.
Answer: b) One or more transactions are aborted (victimized) to break the
cycle.
76.If TS(Ti) < TS(Tj) (timestamp of Tiis less than timestamp of Tj), what typically
happens if Tjtries to read a data item written by Tibefore Tiwrites it? a) Tjproceeds.
b) Tjwaits. c) Tjis aborted. d) Tiis aborted.
Answer: b) Tjwaits (assuming a basic timestamp ordering rule for read-write
conflicts)
78.The primary drawback of basic timestamp ordering is: a) It can lead to cascading
rollbacks. b) It can lead to deadlocks. c) It is difficult to implement. d) It generates
long schedules.
Answer: a) It can lead to cascading rollbacks.
80.A WAL (Write-Ahead Logging) protocol dictates that: a) All writes must be in memory
before they are logged. b) All log records for a change must be written to stable
storage before the corresponding data changes are written to disk. c) Writes should
be deferred until commit. d) Reads are always processed first.
Answer: b) All log records for a change must be written to stable storage
before the corresponding data changes are written to disk.
81.In the Immediate Update recovery technique: a) All updates are written to disk only
after the transaction commits. b) Updates are written to the database disk as they
occur, before commit. c) Updates are stored in a shadow copy of the database. d) No
logging is required.
Answer: b) Updates are written to the database disk as they occur, before
commit.
82.To undo an operation in an Immediate Update system, the recovery manager uses:
a) The system's backup. b) UNDO log records. c) REDO log records. d) Checkpoints.
Answer: b) UNDO log records.
83.In the Deferred Update recovery technique: a) All updates are written to disk as they
occur. b) Updates are temporarily stored in a local buffer and written to the database
disk only when the transaction commits. c) Shadow paging is the primary
mechanism. d) No logging is performed.
Answer: b) Updates are temporarily stored in a local buffer and written to the
database disk only when the transaction commits.
84.In a Deferred Update system, what is generally NOT required for recovery after a
crash? a) REDO log records b) UNDO log records c) Transaction log d) Checkpoints
Answer: b) UNDO log records (since updates are only written on commit, an
abort just means not writing them)
85.Shadow Paging Shadow Paging is a recovery technique that avoids: a) The need
for logging. b) The need for undo operations. c) The need for redo operations. d)
Both undo and redo operations.
Answer: d) Both undo and redo operations.
86.In Shadow Paging, a "shadow directory" points to: a) The most recent version of
database pages. b) The previous (consistent) version of database pages. c) A copy
of the log file. d) The backup of the database.
Answer: b) The previous (consistent) version of database pages.
87.When a transaction commits in Shadow Paging, the current directory becomes the:
a) Backup directory. b) New shadow directory. c) Previous shadow directory. d)
Stable directory.
Answer: d) Stable directory (or the new 'shadow' is promoted to current, and
the old 'current' is discarded or becomes the shadow for the next transaction).
89.A checkpoint in database recovery is used to: a) Rollback all active transactions. b)
Reduce the amount of log that needs to be scanned during recovery. c) Initiate a new
transaction. d) Create a full backup of the database.
Answer: b) Reduce the amount of log that needs to be scanned during
recovery.
90.During the UNDO phase of recovery after a system crash, the recovery manager
processes log records in: a) Forward chronological order. b) Reverse chronological
order. c) Random order. d) Alphabetical order.
Answer: b) Reverse chronological order.
91.During the REDO phase of recovery after a system crash, the recovery manager
processes log records in: a) Forward chronological order. b) Reverse chronological
order. c) Random order. d) Alphabetical order.
Answer: a) Forward chronological order.
92.The BEGIN TRANSACTION, COMMIT, and ROLLBACK commands are part of: a) DDL
(Data Definition Language) b) DML (Data Manipulation Language) c) TCL
(Transaction Control Language) d) DCL (Data Control Language)
Answer: c) TCL (Transaction Control Language)
94.If a transaction fails before its COMMIT point, it enters the: a) Committed state b)
Aborted state c) Active state d) Partially committed state
Answer: b) Aborted state
97.A deadlock graph (wait-for graph) is used in: a) Deadlock prevention. b) Deadlock
detection. c) Deadlock avoidance. d) Concurrency serializability checking.
Answer: b) Deadlock detection.
98.In timestamp ordering, the read_TS(X) for a data item X indicates: a) The largest
timestamp of any transaction that has successfully written X. b) The largest
timestamp of any transaction that has successfully read X. c) The timestamp of the
transaction currently holding a lock on X. d) The time when X was last accessed.
Answer: b) The largest timestamp of any transaction that has successfully
read X.
99.In timestamp ordering, the write_TS(X) for a data item X indicates: a) The largest
timestamp of any transaction that has successfully written X. b) The largest
timestamp of any transaction that has successfully read X. c) The timestamp of the
transaction that last accessed X. d) The current time.
Answer: a) The largest timestamp of any transaction that has successfully
written X.
100. A system crash resulting in loss of volatile storage but preserving non-volatile
storage is known as a: a) Disk failure b) Media failure c) System failure d) Power
failure