DATABASE NOTES(MIDS)
✅ 1. Explain the architecture of ORDBMS
with examples. (5 marks)
ORDBMS (Object-Relational DBMS) combines features of relational databases and object-
oriented databases.
Architecture:
1. Relational Layer
o Traditional tables, rows, columns.
o SQL query processing.
o Example: Student(name, age).
2. Object Layer
o Supports object features like user-defined types (UDTs), classes, inheritance.
o Can store multimedia objects, arrays, complex data.
3. Storage Layer
o Manages how data is stored on disk, indexes, files.
Example:
PostgreSQL allows:
CREATE TYPE address AS (city TEXT, zip INT);
This shows object features.
✅ 2. Differentiate between OODBMS and
ORDBMS. (5 marks)
Feature OODBMS ORDBMS
Data storage Stores objects directly Stores tables + objects
Language OQL SQL + object extensions
Applications CAD/CAM, multimedia Banking, enterprise, complex apps
Schema No tables Tables + UDTs
Examples db4o PostgreSQL, Oracle
Easy summary:
OODBMS = only objects
ORDBMS = tables + objects
✅ 3. Discuss hashing and its types in file
organization. (5 marks)
Hashing is a technique to store records so they can be found quickly using a hash function.
Types of Hashing:
1. Static Hashing
o Number of buckets is fixed.
o Suitable for small, stable data.
o Example: h(key) = key % 10
2. Dynamic Hashing
o Buckets grow or shrink with data.
o Handles large and growing databases.
Types:
o Extendible Hashing → Uses directory that grows.
o Linear Hashing → Buckets split one-by-one gradually.
✅ 4. Explain the role of checkpoints in
recovery. (5 marks)
Checkpoints are markers written to the log showing that the database is in a safe and consistent
state.
Roles:
Reduces recovery time after crash.
Helps identify which transactions need REDO or UNDO.
Avoids scanning the entire log from start.
Makes the system stable and faster during recovery.
Easy example:
At checkpoint, the DB says: “Everything up to here is saved.”
✅ 5. Describe different types of file
organization with examples. (5 marks)
1. Heap (Unordered) File Organization
o Records stored randomly.
o Example: User sign-ups stored in no order.
2. Sequential File Organization
o Records sorted by key.
o Example: Employee payroll list sorted by employee ID.
3. Hash File Organization
o Uses hash function for fast search.
o Example: Searching student by roll number.
4. Clustered File Organization
o Related tables stored near each other.
o Example: Students and their marks stored close.
✅ 6. What are ACID properties? Explain each
with an example. (5 marks)
ACID ensures reliable database transactions.
1. Atomicity – All steps succeed or none.
Example: Money transfer either happens completely or fails completely.
2. Consistency – Data always remains valid.
Example: Total balance remains correct after transfer.
3. Isolation – Transactions do not affect each other.
Example: Two users booking seats don’t interfere.
4. Durability – After commit, data is permanent.
Example: After deposit is committed, crash won’t undo it.
✅ 7. What is serializability? Explain conflict
and view serializability. (5 marks)
Serializability means that concurrent transactions produce the same result as if executed one
after another.
Conflict Serializability
Based on checking conflicting operations (read-write, write-read on same data).
If precedence graph has no cycle, it is conflict-serializable.
View Serializability
Based on checking if schedules read same values and produce same final writes.
More general than conflict serializability.
✅ 8. ARIES Recovery Algorithm (Short Note
– 5 marks)
ARIES = Algorithm for Recovery and Isolation Exploiting Semantics.
Three Phases:
1. Analysis:
o Identify active transactions at crash time.
2. Redo:
o Reapply all actions from log to ensure all updates are done.
3. Undo:
o Undo all incomplete transactions.
Key Features:
Write-Ahead Logging (WAL)
Log Sequence Numbers (LSN)
Efficient crash recovery
✅ 9. What are triggers? Explain with SQL
example. (5 marks)
A trigger is an automatic action executed when INSERT, UPDATE, or DELETE happens.
Example: BEFORE INSERT Trigger
CREATE TRIGGER set_date
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
:NEW.join_date := SYSDATE;
END;
This automatically sets the joining date.
✅ 10. Describe different types of indexes used
in DBMS. (5 marks)
1. Primary Index – Built on primary key.
2. Secondary Index – Built on non-primary attributes.
3. Clustered Index – Changes physical order of table.
4. Non-clustered Index – Separate index structure.
5. Dense Index – Every record has index entry.
6. Sparse Index – Index entry for block only.
7. B+ Tree Index – Most common.
8. Bitmap Index – For low-cardinality fields.
✅ 11. Physical vs Logical Query Optimization
(5 marks)
Logical Optimization Physical Optimization
Rewrites the query logically Selects best physical plan
Uses rules like join reordering, removing Chooses index scan, sort method, join
subqueries algorithms
Example: choosing hash join instead of nested
Example: converting nested query → join
loop
✅ 12. Describe Two-Phase Commit Protocol
(2PC). Why needed? (5 marks)
Used in distributed DBs to ensure atomic commit across multiple sites.
Phases:
1. Prepare Phase:
Coordinator asks all sites: “Can you commit?”
2. Commit Phase:
o If all vote YES → commit
o If any vote NO → abort
Why Needed?
Ensures all databases commit or rollback together.
Prevents inconsistent data across sites.
✅ 13. Bitmap Indexing (5 marks)
Bitmap index uses bit vectors to represent values.
Advantages:
Very fast for AND/OR operations
Requires low storage
Great for columns with few distinct values (low cardinality)
Used in:
Data warehouses
OLAP systems
Gender, region, status fields
✅ 14. Differentiate Shared, Exclusive &
Intention Locks. (5 marks)
Lock Type Meaning Allows
Shared (S) For reading Other shared locks
Exclusive (X) For reading & writing No other lock
Intention (IS/IX) Shows intention to acquire lock on lower level Helps with hierarchical locking
✅ 15. Steps of PL/SQL Trigger Execution +
Example (5 marks)
Steps:
1. Event occurs (INSERT/UPDATE/DELETE).
2. DB checks trigger condition.
3. Trigger body executes.
4. Trigger completes before or after event.
BEFORE INSERT Example
CREATE OR REPLACE TRIGGER before_add_student
BEFORE INSERT ON students
FOR EACH ROW
BEGIN
:NEW.created_at := SYSDATE;
END;
✅ 16. What is Database Auditing? Purpose &
types. (5 marks)
Database auditing means recording who did what in the database.
Purpose:
Security
Detect unauthorized access
Track user actions
Compliance laws (SOX, HIPAA)
Types of Logs:
Access logs (who logged in)
Transaction logs (changes made)
Error logs
Schema change logs
Privilege/role change logs
✅ 17. Locking & Timestamp Ordering (5
marks)
Locking:
Uses S and X locks.
Ensures serializability.
Blocks conflicting operations.
Transactions wait for each other.
Timestamp Ordering:
Each transaction gets a timestamp.
DB allows or rejects operations based on timestamp order.
Ensures older transactions get priority.
Conflicts cause abort & restart.
✅ 18. What is query optimization? Steps &
importance. (5 marks)
Query optimization finds the fastest and cheapest way to execute SQL.
Steps:
1. Parsing
2. Logical optimization
3. Physical optimization
4. Cost estimation
5. Execution plan generation
Importance:
Reduces execution time
Saves memory/CPU
Improves performance
Handles large data efficiently
✅ 19. Phantom, Dirty, Non-repeatable Read
(5 marks)
Dirty Read
Transaction reads uncommitted data.
Non-repeatable Read
Same row read twice gives different values.
Phantom Read
New rows appear when rereading using same condition.
✅ 20. What is Query Execution Plan? How
generated? (5 marks)
A query execution plan is a roadmap showing how the database will execute a query.
How It Is Generated:
1. SQL is parsed.
2. Optimizer generates multiple possible plans.
3. It estimates cost of each (CPU, I/O).
4. Chooses the cheapest plan.
5. Shown to user via EXPLAIN.
Q1. Compare Object-Oriented, Object-
Relational, and Relational Data Models
(Advantages, disadvantages, use cases – Long Answer)
1. Relational Data Model (RDM)
Description:
Stores data in tables (relations) using rows and columns.
Uses primary keys, foreign keys, and SQL.
Normalization removes redundancy.
Advantages:
Simple structure (tables).
Strong mathematical foundation.
SQL is standardized and easy to use.
Highly reliable and secure.
Excellent for structured data.
Disadvantages:
Cannot store complex objects easily.
Not suitable for multimedia or nested data.
Mapping objects to tables (ORM) is difficult.
Use Cases:
Banking systems
Universities
Online shopping databases
Inventory systems
2. Object-Oriented Data Model (OODM)
Description:
Stores data in the form of objects (similar to OOP).
Supports inheritance, polymorphism, encapsulation.
Objects contain both data and methods.
Advantages:
Perfect for complex and multimedia data.
No need for object-to-table mapping.
Supports relationships and behaviors directly.
Disadvantages:
No standard query language.
Difficult for beginners.
Poor support in commercial systems.
Use Cases:
CAD/CAM systems
Robotics
Multimedia applications (images, video)
Real-time simulations
3. Object-Relational Data Model (ORDM)
Description:
Hybrid of relational + object-oriented models.
Supports tables, but also objects, user-defined types, large objects, arrays.
Uses extended SQL.
Advantages:
Retains SQL + adds support for complex data.
Better performance when storing objects.
Supports inheritance and custom data types.
Disadvantages:
More complex than relational DBMS.
Higher learning curve.
Performance overhead if misused.
Use Cases:
GIS systems (maps)
Medical imaging databases
Social networks
Scientific research data
Summary Table
Feature Relational Object-Oriented Object-Relational
Structure Tables Objects Tables + Objects
Query Language SQL OQL Extended SQL
Data Type Support Simple Complex Complex + Relational
Examples MySQL, SQL Server db4o, ObjectStore PostgreSQL, Oracle
✅ Q2. Explain: (a) ORDM (b) OODM, Their
Advantages and Applications
1.
2. Physical optimization
3. Cost estimation
4. Execution plan generation
Importance:
Reduces execution time
Saves memory/CPU
Improves performance
Handles large data efficiently
✅ 19. Phantom, Dirty, Non-repeatable Read
(5 marks)
Dirty Read
Transaction reads uncommitted data.
Non-repeatable Read
Same row read twice gives different values.
Phantom Read
New rows appear when rereading using same condition.
✅ 20. What is Query Execution Plan? How
generated? (5 marks)
A query execution plan is a roadmap showing how the database will execute a query.
How It Is Generated:
1. SQL is parsed.
2. Optimizer generates multiple possible plans.
3. It estimates cost of each (CPU, I/O).
4. Chooses the cheapest plan.
5. Shown to user via EXPLAIN.
Long questins
✅ Q1. Compare Object-Oriented, Object-
Relational, and Relational Data Models
(Advantages, disadvantages, use cases – Long Answer)
1. Relational Data Model (RDM)
Description:
Stores data in tables (relations) using rows and columns.
Uses primary keys, foreign keys, and SQL.
Normalization removes redundancy.
Advantages:
Simple structure (tables).
Strong mathematical foundation.
SQL is standardized and easy to use.
Highly reliable and secure.
Excellent for structured data.
Disadvantages:
Cannot store complex objects easily.
Not suitable for multimedia or nested data.
Mapping objects to tables (ORM) is difficult.
Use Cases:
Banking systems
Universities
Online shopping databases
Inventory systems
2. Object-Oriented Data Model (OODM)
Description:
Stores data in the form of objects (similar to OOP).
Supports inheritance, polymorphism, encapsulation.
Objects contain both data and methods.
Advantages:
Perfect for complex and multimedia data.
No need for object-to-table mapping.
Supports relationships and behaviors directly.
Disadvantages:
No standard query language.
Difficult for beginners.
Poor support in commercial systems.
Use Cases:
CAD/CAM systems
Robotics
Multimedia applications (images, video)
Real-time simulations
3. Object-Relational Data Model (ORDM)
Description:
Hybrid of relational + object-oriented models.
Supports tables, but also objects, user-defined types, large objects, arrays.
Uses extended SQL.
Advantages:
Retains SQL + adds support for complex data.
Better performance when storing objects.
Supports inheritance and custom data types.
Disadvantages:
More complex than relational DBMS.
Higher learning curve.
Performance overhead if misused.
Use Cases:
GIS systems (maps)
Medical imaging databases
Social networks
Scientific research data
Summary Table
Feature Relational Object-Oriented Object-Relational
Structure Tables Objects Tables + Objects
Query Language SQL OQL Extended SQL
Data Type Support Simple Complex Complex + Relational
Examples MySQL, SQL Server db4o, ObjectStore PostgreSQL, Oracle
✅ Q2. Explain: (a) ORDM (b) OODM, Their
Advantages and Applications
(a) Object-Relational Data Model (ORDM)
Definition:
ORDM extends the relational model by adding object-oriented features such as UDTs,
inheritance, nested tables, BLOBs, and methods.
Features:
User-defined types
Complex objects
Reference types
Table inheritance
Large object storage
Advantages:
Supports both structured and complex data
Backward compatibility with SQL
Efficient storage of multimedia
Better modeling of real-world entities
Applications:
Medical image systems
Scientific research databases
Banking with complex transaction data
Social media (posts, images, comments)
(b) Object-Oriented Data Model (OODM)
Definition:
Stores data as objects with state and behavior.
Features:
Identity (OID)
Encapsulation
Methods inside objects
Inheritance and polymorphism
Advantages:
Eliminates mismatch between programming objects and database
Good performance for complex data
Perfect for recursive relationships
Can store any type of object
Applications:
CAD/CAM
Robotics
Multimedia systems
Real-time simulations
✅ Q3. Describe: Transaction Processing,
ACID, Transaction States, Problems &
Prevention
1. Transaction Processing
A transaction is a logical unit of work (e.g., money transfer).
DBMS ensures transactions are correct, consistent, and reliable.
2. ACID Properties
Atomicity – All steps succeed or none.
Consistency – Database remains valid after transaction.
Isolation – Each transaction works independently.
Durability – Committed data is permanent.
3. Transaction States
1. Active
2. Partially committed
3. Committed
4. Failed
5. Terminated (Aborted)
4. Problems in Transactions
1. Dirty Read – Reading uncommitted data
2. Non-repeatable Read – Same row read twice gives different values
3. Phantom Read – New rows appear
4. Lost Update – Two transactions overwrite each other
5. Deadlock – Two transactions wait forever for each other
5. How DBMS Prevents These Problems
Locks (S/X)
Two-Phase Locking (2PL)
Timestamp Ordering
Deadlock detection & prevention
Isolation levels
Write-ahead logging
✅ Q4. Query Processing Phases & Cost-Based
Optimization
1. Query Processing Phases
1. Parsing & Translation – SQL → parse tree
2. Query Optimization – Best plan selected
3. Plan Generation – Execution plan created
4. Execution – Operators run (scan, join, sort)
2. Cost-based Optimization
Uses CPU/I/O cost to select best execution plan.
Techniques:
1. Join Order Selection
o Choosing order of joins
o Example: join smallest table first
2. Access Paths
o Table scan
o Index scan
o Range scan
3. Indexing Strategies
o Use B+ tree for range queries
o Bitmap for low-cardinality columns
o Clustered index for sorted reports
The optimizer picks the cheapest plan using statistics.
✅ Q5. Database Integrity & Security
(Integrity constraints, authorization, authentication, encryption, auditing, SQL injection)
1. Integrity Constraints
Ensure data correctness.
Primary key
Foreign key
Unique
Check
Not null
2. Authorization
Controls what users can do.
Examples: SELECT, INSERT, UPDATE, DELETE, GRANT, REVOKE.
3. Authentication
Confirms identity.
Methods: passwords, biometrics, multi-factor authentication.
4. Encryption
Protects data from unauthorized access.
Types:
Transparent Data Encryption (TDE)
Column-level encryption
5. Database Auditing
Tracks user actions like Login, Query execution, Schema changes.
6. SQL Injection Prevention
Use prepared statements
Input sanitization
Avoid dynamic SQL
Enable WAF (Web Application Firewall)
✅ Q6. Transaction Processing, Concurrency
Control & Recovery Methods
1. Transaction Processing
Ensures correctness of operations like insert, update, delete.
2. Concurrency Control Techniques
Locks (S, X, IS, IX)
Two-Phase Locking (2PL)
Timestamp Ordering
Optimistic concurrency
Multiversion Concurrency Control (MVCC)
3. Recovery Methods
Undo (Rollback)
Reverses uncommitted changes.
Redo
Reapplies logged changes to ensure durability.
Checkpoints
Mark a stable state to reduce recovery work.
ARIES Algorithm
Analysis
Redo
Undo
Uses WAL (Write-Ahead Logging).
4. Why Essential?
Prevents corruption
Maintains ACID properties
Ensures reliability during crashes
Supports concurrent users safely
✅ Q7. File Organization Techniques (Heap,
Sequential, Hash, Indexed)
1. Heap File Organization
Records stored randomly.
Advantages: Fast insert.
Applications: Temporary tables.
2. Sequential File Organization
Records stored in sorted order.
Advantages: Fast reading, range queries.
Applications: Payroll system.
3. Hash File Organization
Hash function decides record location.
Advantages: Fast search for equality queries.
Applications: Search by ID, roll number.
4. Indexed File Organization
Uses separate index structure (like B+ Tree).
Advantages: Very fast search.
Applications: Large databases, search-heavy systems