LearnPracticeExamsMocks

Clear practice, useful explanations and steady progress for exam preparation.

Study

AptitudeLogical reasoningVerbal abilityTechnical aptitudeAI & modern dev

Explore

Practice libraryLocal progressExam patternsFor collegesSearchAbout AISEAFAQ

Trust & support

ContactReport a problemContent correctionsAccessibility
© 2026 AISEA. Built for focused learning.Privacy · Terms · Editorial policy
Home
›Technical Aptitude
›DBMS
Technical
Programming Concepts
Data Structures
Algorithms
DBMSPractice
Operating Systems
Computer Networks
C Programming
Java
Python

DBMS and SQL MCQs with answers and explanations

Study relational models, keys, normalisation, transactions, indexes and SQL query concepts. Practise DBMS questions with explained answers, including SQL topics, for placement tests and GATE CS preparation.

194 practice questionsPage updated 24 Sept 2026Review metadata pendingPractice questions
Practise this concept

Database Management Systems (DBMS) is software that enables users to create, manage, and manipulate databases. It provides an interface between users/applications and the database, ensuring data integrity, security, and efficient retrieval through structured query languages like SQL. Understanding DBMS fundamentals is essential for technical interviews and software development roles.

Key formulas and rules

8 rules
1

Cartesian Product Cardinality: ∣R×S∣=∣R∣×∣S∣, with degree deg(R×S)=deg(R)+deg(S)

2

Natural Join Cardinality Bounds: 0≤∣R⋈S∣≤∣R∣×∣S∣ (at most ∣R∣×∣S∣ when no attributes overlap, and at most ∣R∣ when the join is on a foreign key in R referencing a unique primary key in S)

3

Set Operations: Degree of R∪S and R∩S equals deg(R), requiring union-compatibility

4

First Normal Form (1NF): All column values must be atomic; no repeating groups or multi-valued attributes

5

Second Normal Form (2NF): Satisfies 1NF and contains no partial dependencies (every non-prime attribute is fully functionally dependent on every candidate key)

6

Third Normal Form (3NF): Satisfies 2NF and contains no transitive dependencies (for every FD X→Y, either X is a superkey or Y is a prime attribute)

7

Boyce-Codd Normal Form (BCNF): For every non-trivial functional dependency X→Y, X must be a superkey

8

ACID Transactions: Atomicity (all-or-nothing), Consistency (integrity constraints preserved), Isolation (serializability), Durability (committed updates persist)

Key concepts

Data Models and Database Architecture

The three-schema architecture consists of: (1) External Level - user views and how data appears to specific users; (2) Conceptual Level - logical structure of the entire database including entities, relationships, and constraints; (3) Internal Level - physical storage structure and access methods. Common data models include: Hierarchical (tree structure), Network (graph structure), Relational (tables with rows and columns), and Object-Oriented. The Relational Model uses tables (relations) where rows are tuples and columns are attributes, with keys (Primary, Foreign, Candidate, Super) defining relationships.

SQL Operations and Query Processing

SQL commands are categorized as: DDL (Data Definition Language) - CREATE, ALTER, DROP, TRUNCATE for schema modification; DML (Data Manipulation Language) - SELECT, INSERT, UPDATE, DELETE for data operations; DCL (Data Control Language) - GRANT, REVOKE for permissions; TCL (Transaction Control Language) - COMMIT, ROLLBACK, SAVEPOINT. Important SQL operations include: JOINs (INNER, LEFT, RIGHT, FULL OUTER, CROSS, SELF), subqueries (correlated and non-correlated), aggregate functions (COUNT, SUM, AVG, MAX, MIN), GROUP BY with HAVING clause, and set operations (UNION, INTERSECT, EXCEPT). Query optimization involves indexes, query rewriting, and understanding execution plans.

Normalization and Functional Dependencies

Normalization is the process of organizing data to reduce redundancy and improve integrity. Functional Dependency (FD): X -> Y means X uniquely determines Y. Closure of an attribute set (X+) with respect to FDs finds all attributes functionally determined by X. Normal Forms in order: 1NF eliminates repeating groups; 2NF eliminates partial dependencies (non-prime attributes must depend on entire candidate key); 3NF eliminates transitive dependencies; BCNF requires every determinant to be a superkey. Higher forms (4NF, 5NF) handle multi-valued and join dependencies. Decomposition must be lossless (natural join recovers original) and dependency-preserving (all FDs are preserved in decomposed relations).

Transaction Management and Concurrency Control

A transaction is a logical unit of work with ACID properties: Atomicity (all-or-nothing execution), Consistency (valid state transitions), Isolation (concurrent transactions don't interfere), Durability (committed changes persist). Concurrency issues include: Lost Update, Dirty Read, Non-Repeatable Read, Phantom Read. Locking mechanisms: Binary Locks (S/X), Shared/Exclusive Locks, Two-Phase Locking (2PL - growing then shrinking phase ensures serializability). Deadlock handling: Prevention (wait-die, wound-wait), Avoidance (Banker's algorithm), Detection (wait-for graph), Recovery. Timestamp ordering assigns unique timestamps to transactions. Recovery techniques: Deferred Update (redo only), Immediate Update (undo-redo), Shadow Paging, Checkpoints.

Indexing and Query Optimization

Indexes speed up data retrieval at the cost of storage and maintenance overhead. Types: Primary Index (on ordering key field), Secondary Index (on non-ordering fields), Clustered Index (determines physical order), Non-clustered Index (separate structure with pointers), Dense Index (entry for every record), Sparse Index (entry for each block). B-Trees and B+ Trees are balanced tree structures for efficient searching, insertion, and deletion. Hash indexes use hash functions for direct access. Query optimization involves: cost-based selection of access paths, join ordering, use of indexes, materialized views, and understanding query execution plans. The optimizer estimates costs based on statistics (cardinality, selectivity, distribution).

ER Model and Database Design

The Entity-Relationship (ER) Model is a high-level conceptual data model. Components: Entities (objects with independent existence - strong/weak), Attributes (simple, composite, multi-valued, derived, key), Relationships (associations between entities with cardinality ratios: 1:1, 1:N, M:N). ER Diagram notation: rectangles for entities, ellipses for attributes, diamonds for relationships, lines connecting them with cardinality markers. Extended ER features: Specialization (top-down, ISA hierarchy with disjoint/overlapping constraints), Generalization (bottom-up), Aggregation (treating relationship as entity). Converting ER to Relational: Entities become tables, M:N relationships become junction tables, weak entities include owner's key, ISA hierarchies use single table, multiple tables, or separate relations.

Check the idea while it is fresh.Open a focused exercise without losing this article.Practise this concept

Worked examples

Example 1

Given relation R(A, B, C, D) with functional dependencies: A -> B, B -> C, C -> D. Is R in 3NF? If not, decompose to 3NF.

Solution

Step 1: Find candidate key.
A+={A,B,C,D} (since A→B, B→C, C→D).
So A is the only candidate key.

Step 2: Check for partial dependencies (2NF).
Since the key is single attribute A, there are no partial dependencies. R is in 2NF.

Step 3: Check for transitive dependencies (3NF).
A→B and B→C: This is a transitive dependency (non-prime B determines non-prime C).
B→C and C→D: This is another transitive dependency.
So R is NOT in 3NF.

Step 4: Decompose to 3NF using synthesis algorithm.
From A→B: Create R1​(A,B) with key A
From B→C: Create R2​(B,C) with key B
From C→D: Create R3​(C,D) with key C

Step 5: Check if original key is preserved.
Yes, A is in R1​.

Final decomposition: R1​(A,B), R2​(B,C), R3​(C,D)
All are in 3NF and dependency-preserving.

Example 2

Two transactions: T1 reads A, writes A; T2 reads A, writes A. Show a schedule that results in Lost Update and explain how 2PL prevents it.

Solution

Step 1: Lost Update Example (non-serializable schedule):
Time 1: T1: Read(A) -> A=100
Time 2: T2: Read(A) -> A=100
Time 3: T1: A=A+10, Write(A) -> A=110
Time 4: T2: A=A+20, Write(A) -> A=120

Result: T1's update is lost! Correct should be 130 (100+10+20).

Step 2: How 2PL Prevents This:
In Two-Phase Locking:
- Growing phase: Acquire locks
- Shrinking phase: Release locks (no new locks after first release)

Step 3: 2PL Schedule:
Time 1: T1: Lock-S(A) -> Read(A)
Time 2: T1: Upgrade to Lock-X(A) -> T1 holds exclusive lock
Time 3: T2: Lock-S(A) -> BLOCKED (T1 has X lock)
Time 4: T1: Write(A), Unlock(A)
Time 5: T2: Lock-S(A) granted -> Read(A) gets 110
Time 6: T2: Upgrade to Lock-X(A) -> Write(A) = 130

Result: 2PL ensures serializability. Final value is correct: 130.

Example 3

Given Employee(EID, Name, DeptID, Salary, ManagerID) and Department(DeptID, DName, Location). Write SQL to find employees who earn more than their department's average salary, and explain if an index would help.

Solution

Step 1: SQL Query:
SELECT e.EID, e.Name, e.Salary, d.DName
FROM Employee e
JOIN Department d ON e.DeptID = d.DeptID
WHERE e.Salary > (
SELECT AVG(e2.Salary)
FROM Employee e2
WHERE e2.DeptID = e.DeptID
);

Step 2: Alternative with JOIN:
SELECT e.EID, e.Name, e.Salary, d.DName, avg_sal.avg_salary
FROM Employee e
JOIN Department d ON e.DeptID = d.DeptID
JOIN (
SELECT DeptID, AVG(Salary) as avg_salary
FROM Employee
GROUP BY DeptID
) avg_sal ON e.DeptID = avg_sal.DeptID
WHERE e.Salary > avg_sal.avg_salary;

Step 3: Index Analysis:
- Index on Employee(DeptID): Helps join and group by operations, significantly improves correlated subquery
- Index on Employee(Salary): Less helpful here (range comparison after join)
- Composite index on Employee(DeptID, Salary): Most effective - supports both grouping and salary comparison
- Index on Department(DeptID): Helps join (usually primary key, already indexed)

Step 4: Query Plan Considerations:
With proper indexing, optimizer can use index seek for department grouping, avoiding full table scan. The correlated subquery version may be rewritten as join by optimizer.

Example 4

Convert this ER scenario to relational schema: University has Departments (DeptID, Name). Each Department has Professors (ProfID, Name, Specialization). A Professor belongs to exactly one Department. Professors teach Courses (CourseID, Title, Credits). A Course can be taught by multiple Professors, and a Professor can teach multiple Courses. Some Courses are prerequisites for others.

Solution

Step 1: Identify Entities and Relationships:
- Department: Strong entity
- Professor: Strong entity, belongs to Department (1:N)
- Course: Strong entity
- Teaches: M:N between Professor and Course
- Prerequisite: M:N self-referencing on Course

Step 2: Relational Schema:

Department(DeptID, Name)
Primary Key: DeptID

Professor(ProfID, Name, Specialization, DeptID)
Primary Key: ProfID
Foreign Key: DeptID REFERENCES Department(DeptID)
(1:N - Professor belongs to one Department)

Course(CourseID, Title, Credits)
Primary Key: CourseID

Teaches(ProfID, CourseID, Semester, Year)
Primary Key: (ProfID, CourseID, Semester, Year)
Foreign Key: ProfID REFERENCES Professor(ProfID)
Foreign Key: CourseID REFERENCES Course(CourseID)
(M:N relationship with its own attributes)

Prerequisite(CourseID, PrereqCourseID)
Primary Key: (CourseID, PrereqCourseID)
Foreign Key: CourseID REFERENCES Course(CourseID)
Foreign Key: PrereqCourseID REFERENCES Course(CourseID)
(M:N self-referencing relationship)

Step 3: Notes:
- Department-Professor is 1:N, so DeptID is stored in Professor
- Teaches is M:N, so it becomes a separate table
- Prerequisite is M:N on same entity, requiring two FKs to Course
- Composite PK in Prerequisite prevents duplicate prerequisites
- Semester and Year are descriptive attributes of the Teaches relationship

Representative solved questions

See the kind of question in this topic before opening the full practice set.

Question 1

Which normal form eliminates partial dependencies?

  1. A.

    1NF

  2. B.

    2NF

  3. C.

    3NF

  4. D.

    BCNF

Answer: B. 2NF

Explanation

Step 1: 1NF eliminates repeating groups and ensures atomic values.
Step 2: 2NF eliminates partial dependencies (non-key attributes must depend on the entire key).
Step 3: A partial dependency occurs when a non-key attribute depends on part of a composite key.
Answer: 2NF

Sources and review notes

This is an AISEA-authored practice question.

Review status: accepted · Reviewed 2026-08-13 · structure and answer-key checks, editorial quality checks, duplicate screening

Question 2

Which type of join returns all records when there is a match in either left or right table?

  1. A.

    INNER JOIN

  2. B.

    LEFT JOIN

  3. C.

    FULL OUTER JOIN

  4. D.

    CROSS JOIN

Answer: C. FULL OUTER JOIN

Explanation

Step 1: INNER JOIN returns only matching records from both tables.
Step 2: LEFT JOIN returns all records from left table and matched records from right.
Step 3: FULL OUTER JOIN returns all records when there is a match in either table, filling NULLs where no match exists.
Answer: FULL OUTER JOIN

Sources and review notes

This is an AISEA-authored practice question.

Review status: accepted · Reviewed 2026-08-13 · structure and answer-key checks, editorial quality checks, duplicate screening

Question 3

Which SQL statement removes all records from a table but keeps the table structure?

  1. A.

    DELETE

  2. B.

    DROP

  3. C.

    TRUNCATE

  4. D.

    REMOVE

Answer: C. TRUNCATE

Explanation

Step 1: DELETE removes specific rows based on WHERE clause (can be rolled back).
Step 2: DROP removes the entire table including structure and data.
Step 3: TRUNCATE removes all rows quickly, cannot be rolled back in some DBMS, preserves table structure.
Answer: TRUNCATE

Sources and review notes

This is an AISEA-authored practice question.

Review status: accepted · Reviewed 2026-08-13 · structure and answer-key checks, editorial quality checks, duplicate screening

Common mistakes and useful habits

  • Always identify candidate keys first when analyzing normal forms - every normal form check depends on knowing what the keys are
  • For SQL queries involving multiple tables, draw the join diagram mentally: INNER JOIN returns matching rows only, LEFT JOIN returns all from left with NULLs for non-matches
  • In transaction questions, check for serializability using precedence graph (conflict serializability) or view equivalence (view serializability)
  • Remember: BCNF is stricter than 3NF. A relation in BCNF is automatically in 3NF, but not vice versa. Decomposition to BCNF may lose some functional dependencies
  • When calculating index selectivity: High cardinality columns (many unique values) benefit more from B+ tree indexes; low cardinality may favor bitmap indexes
  • For ER-to-Relational conversion: 1:N relationships place the '1' side key on the 'N' side; M:N relationships always become a separate table with both keys

Ready to test your understanding?

Work through 194 questions with explanations after each answer.

Start practice
Next topic: Operating Systems →

Keep building the same skill family.

Programming Concepts

Variables, loops, functions, recursion

Open practice
Data Structures

Arrays, stacks, queues, trees, graphs

Open practice
Algorithms

Sorting, searching, complexity analysis

Open practice
On this page
Formulas and rulesKey conceptsWorked examplesRepresentative questionsCommon mistakesRelated practice

Suggest a correction