0% found this document useful (0 votes)
4 views

DBMS Interview Questions

The document provides a comprehensive list of 47 DBMS interview questions along with detailed answers and examples. It covers various topics including basic DBMS concepts, SQL commands, transactions, advanced DBMS concepts, stored procedures, triggers, performance optimization, and real-world scenarios. Each section includes definitions, examples, and explanations of key terms and functionalities related to database management systems.

Uploaded by

Ajay Choudhary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

DBMS Interview Questions

The document provides a comprehensive list of 47 DBMS interview questions along with detailed answers and examples. It covers various topics including basic DBMS concepts, SQL commands, transactions, advanced DBMS concepts, stored procedures, triggers, performance optimization, and real-world scenarios. Each section includes definitions, examples, and explanations of key terms and functionalities related to database management systems.

Uploaded by

Ajay Choudhary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

DBMS Interview Questions

tell me the all the questions asked in dbms in iterview

Here is a comprehensive list of DBMS interview questions:

Basic DBMS Questions:

1. What is a Database Management System (DBMS)?


2. What are the different types of DBMS?
3. What is the difference between DBMS and RDBMS?
4. What is a primary key?
5. What is a foreign key?
6. What is a candidate key?
7. What is a composite key?
8. What is a super key?
9. What is a unique key?
10. What are constraints in DBMS?

SQL & Query-Based Questions:

11. What are the different types of SQL commands?


12. Explain DDL, DML, DCL, and TCL with examples.
13. What is the difference between DELETE, TRUNCATE, and DROP?
14. What is Normalization, and what are its different forms?
15. What is denormalization?
16. Write an SQL query to find the second highest salary.
17. Write an SQL query to find duplicate records in a table.
18. How do you use JOINs in SQL? Explain different types of JOINs.
19. What is Self Join and Cross Join?
20. What is an Index, and how does it improve query performance?

Transactions & Concurrency Control:

21. What is a Transaction in DBMS?


22. What are ACID properties in DBMS?
23. What is dirty read, phantom read, and non-repeatable read?
24. What are different isolation levels?
25. What is a deadlock? How to prevent it?
26. What are locks in DBMS, and how do they work?
27. What is Two-Phase Locking (2PL)?

Advanced DBMS Concepts:

28. What is sharding in DBMS?


29. What is database partitioning?

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/12
30. What are views in SQL, and how are they different from tables?
31. What are materialized views?
32. Explain NoSQL databases and their types.
33. What is the difference between SQL and NoSQL?
34. What is CAP theorem in distributed databases?
35. What is eventual consistency?
36. What is database replication, and what are its types?

Stored Procedures & Triggers:

37. What is a stored procedure?


38. What is a trigger in SQL?
39. How are stored procedures different from functions?
40. What is cascading delete and cascading update?

Performance Optimization & Indexing:

41. What are clustered and non-clustered indexes?


42. What is a B-tree index?
43. How does query optimization work in DBMS?
44. What is the use of EXPLAIN PLAN in SQL?

Real-World & Scenario-Based Questions:

45. How would you design a database for an e-commerce application?


46. How would you handle millions of concurrent database requests?
47. How do you implement database backup and recovery?

Would you like answers to any of these questions?

give me answers to all the 47 questions with examples

Here are the answers to all 47 DBMS interview questions with examples:

Basic DBMS Questions


1. What is a Database Management System (DBMS)?

A DBMS is software that allows users to create, manage, and manipulate databases efficiently. It
provides tools to store, retrieve, update, and delete data.

Example: MySQL, PostgreSQL, MongoDB, Oracle DB.

2. What are the different types of DBMS?

1. Hierarchical DBMS – Data is organized in a tree-like structure.


Example: IBM’s IMS.

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/12
2. Network DBMS – Uses a graph structure with multiple parent-child relationships.
Example: Integrated Data Store (IDS).
3. Relational DBMS (RDBMS) – Uses tables to store data with relationships.
Example: MySQL, PostgreSQL.
4. Object-Oriented DBMS – Stores data as objects, similar to OOPs.
Example: ObjectDB, db4o.

3. What is the difference between DBMS and RDBMS?

Feature DBMS RDBMS

Structure Stores data as files Stores data in tables


Relationship No relationships Relationships via foreign keys

Normalization No support Supports normalization


Example XML, File System MySQL, Oracle, PostgreSQL

4. What is a Primary Key?

A primary key is a column (or set of columns) that uniquely identifies each row in a table.
Example:

sql

CREATE TABLE Students (


StudentID INT PRIMARY KEY,
Name VARCHAR(50)
);

5. What is a Foreign Key?

A foreign key is a column in one table that refers to the primary key of another table.

Example:

sql

CREATE TABLE Orders (


OrderID INT PRIMARY KEY,
StudentID INT,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID)
);

6. What is a Candidate Key?

A candidate key is a column (or combination) that can be a primary key.


Example:

sql

CREATE TABLE Employee (


EmpID INT,

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/12
Email VARCHAR(100),
PhoneNumber VARCHAR(15),
PRIMARY KEY (EmpID),
UNIQUE (Email, PhoneNumber)
);

Both `Email` and `PhoneNumber` are candidate keys.

7. What is a Composite Key?

A composite key is a combination of two or more columns that uniquely identifies a row.
Example:

sql

CREATE TABLE StudentCourse (


StudentID INT,
CourseID INT,
PRIMARY KEY (StudentID, CourseID)
);

8. What is a Super Key?

A super key is a set of one or more columns that uniquely identifies a row.

9. What is a Unique Key?

A unique key ensures all values in a column are unique but allows NULL values.
Example:

sql

CREATE TABLE Employees (


EmpID INT PRIMARY KEY,
Email VARCHAR(100) UNIQUE
);

10. What are Constraints in DBMS?

Constraints enforce rules on data in a table.

NOT NULL – Ensures a column cannot be NULL.


UNIQUE – Ensures all values are unique.
PRIMARY KEY – Unique and not NULL.
FOREIGN KEY – Enforces a relationship.
CHECK – Ensures values meet a condition.
DEFAULT – Assigns a default value.

Example:

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/12
sql

CREATE TABLE Employees (


EmpID INT PRIMARY KEY,
Age INT CHECK (Age >= 18)
);

SQL & Query-Based Questions


11. What are the different types of SQL commands?

1. DDL (Data Definition Language): `CREATE`, `ALTER`, `DROP`.


2. DML (Data Manipulation Language): `INSERT`, `UPDATE`, `DELETE`.
3. DCL (Data Control Language): `GRANT`, `REVOKE`.
4. TCL (Transaction Control Language): `COMMIT`, `ROLLBACK`.

12. Explain DDL, DML, DCL, and TCL with examples.

sql

-- DDL Example
CREATE TABLE Users (UserID INT PRIMARY KEY, Name VARCHAR(50));

-- DML Example
INSERT INTO Users VALUES (1, 'John');

-- DCL Example
GRANT SELECT ON Users TO 'user1';

-- TCL Example
BEGIN TRANSACTION;
UPDATE Users SET Name='Alice' WHERE UserID=1;
COMMIT;

13. What is the difference between DELETE, TRUNCATE, and DROP?

Command Deletes Data? Removes Structure? Rollback?


DELETE Yes (row-wise) No Yes
TRUNCATE Yes (all rows) No No
DROP Yes Yes No

14. What is Normalization and its different forms?

Normalization eliminates redundancy.

1. 1NF (First Normal Form): Each column has atomic values.


2. 2NF (Second Normal Form): No partial dependencies.
3. 3NF (Third Normal Form): No transitive dependencies.
4. BCNF (Boyce-Codd Normal Form): Each determinant is a candidate key.

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 5/12
15. What is Denormalization?

Denormalization introduces redundancy for performance optimization.

16. SQL Query to Find Second Highest Salary

sql

SELECT MAX(Salary) FROM Employees WHERE Salary < (SELECT MAX(Salary) FROM Employees);

17. SQL Query to Find Duplicate Records

sql

SELECT Name, COUNT(*) FROM Students GROUP BY Name HAVING COUNT(*) > 1;

18. What are Joins in SQL?

1. INNER JOIN: Matches common rows.


2. LEFT JOIN: All rows from left, matching from right.
3. RIGHT JOIN: All rows from right, matching from left.
4. FULL JOIN: All rows from both.

19. What is Self Join?

A Self Join joins a table with itself.

sql

SELECT A.Name, B.Manager FROM Employees A


JOIN Employees B ON A.ManagerID = B.EmpID;

20. What is an Index?

An index speeds up searches.

sql

CREATE INDEX idx_name ON Employees(Name);

21-47 (Advanced Questions)

Due to space constraints, I'll summarize key answers:

ACID Properties: Ensure reliable transactions.


Isolation Levels: Read Uncommitted, Read Committed, Repeatable Read, Serializable.
Deadlocks: Occurs when two processes wait on each other.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 6/12
Sharding: Distributing data across databases.
CAP Theorem: Trade-offs between Consistency, Availability, and Partition Tolerance.
Stored Procedures: Predefined SQL code execution.

Would you like detailed answers for a specific question, or should I continue answering all in detail?

ans all the other question from 21 to 47

Here are the remaining answers (Questions 21 to 47) in detail:

Transactions & Concurrency Control


21. What is a Transaction in DBMS?

A transaction is a unit of work that is executed as a whole. It consists of multiple operations that must
be executed entirely or not at all.
Example:

sql

BEGIN TRANSACTION;
UPDATE Accounts SET Balance = Balance - 500 WHERE AccountID = 1;
UPDATE Accounts SET Balance = Balance + 500 WHERE AccountID = 2;
COMMIT;

22. What are ACID Properties in DBMS?

ACID properties ensure transaction reliability:

1. Atomicity: The transaction is all-or-nothing.


2. Consistency: Database remains in a valid state.
3. Isolation: Transactions execute independently.
4. Durability: Changes are permanent after commit.

23. What is Dirty Read, Phantom Read, and Non-Repeatable Read?

Dirty Read: Reads uncommitted data from another transaction.


Non-Repeatable Read: Same query returns different results within a transaction.
Phantom Read: A transaction sees new rows inserted by another transaction.

24. What are different isolation levels?

1. Read Uncommitted: Allows dirty reads.


2. Read Committed: Prevents dirty reads but allows non-repeatable reads.
3. Repeatable Read: Prevents dirty and non-repeatable reads.

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 7/12
4. Serializable: Highest isolation level, prevents all inconsistencies.

sql

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

25. What is a Deadlock? How to Prevent It?

A deadlock occurs when two transactions wait indefinitely for each other to release locks.

Prevention Techniques:

Implement timeout mechanisms.


Follow a consistent locking order.
Use deadlock detection algorithms.

26. What are Locks in DBMS and How Do They Work?

Locks control concurrent access:

Shared Lock (S): Multiple transactions can read.


Exclusive Lock (X): Only one transaction can modify.

sql

LOCK TABLE Employees IN EXCLUSIVE MODE;

27. What is Two-Phase Locking (2PL)?

A protocol ensuring serializability:

1. Growing phase: Transaction acquires locks.


2. Shrinking phase: Transaction releases locks.

Advanced DBMS Concepts


28. What is Sharding in DBMS?

Sharding is splitting a large database into smaller, manageable parts across different servers to
improve scalability.

29. What is Database Partitioning?

Partitioning divides a database into smaller pieces based on a criterion like range or hash.

sql

PARTITION BY RANGE (Year);

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 8/12
30. What are Views in SQL?

A view is a virtual table based on an SQL query.

sql

CREATE VIEW HighSalary AS


SELECT Name, Salary FROM Employees WHERE Salary > 50000;

31. What are Materialized Views?

Materialized views store the query result physically to improve performance.

sql

CREATE MATERIALIZED VIEW SalesReport AS


SELECT SUM(Sales) FROM Orders;

32. Explain NoSQL Databases and Their Types.

NoSQL databases handle large-scale, unstructured data.

Types:

1. Key-Value Stores (Redis)


2. Document Stores (MongoDB)
3. Column Stores (Cassandra)
4. Graph Databases (Neo4j)

33. Difference Between SQL and NoSQL?

Feature SQL NoSQL

Structure Tables Documents, Key-Value, etc.

Schema Fixed Flexible


Transactions ACID BASE (Eventual Consistency)

Example MySQL MongoDB

34. What is CAP Theorem?

A distributed system can only achieve 2 out of 3:

1. Consistency (C) – Every read gets the latest write.


2. Availability (A) – System is always responsive.
3. Partition Tolerance (P) – System works despite network failures.

35. What is Eventual Consistency?

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 9/12
In distributed databases, eventual consistency ensures data synchronizes over time instead of
immediately.
Example: DNS updates across servers.

36. What is Database Replication?

Replication creates copies of a database to improve availability.

Types:

Master-Slave Replication
Multi-Master Replication

Stored Procedures & Triggers


37. What is a Stored Procedure?

A stored procedure is a precompiled SQL script stored in the database.

sql

CREATE PROCEDURE GetEmployees()


AS
BEGIN
SELECT * FROM Employees;
END;

38. What is a Trigger in SQL?

A trigger is an automatic action executed before/after events like INSERT, UPDATE, DELETE.

sql

CREATE TRIGGER EmployeeTrigger


AFTER INSERT ON Employees
FOR EACH ROW
BEGIN
INSERT INTO AuditLog(EmployeeID, Action) VALUES (NEW.EmpID, 'Inserted');
END;

39. How are Stored Procedures Different from Functions?

Feature Stored Procedure Function


Returns Value? No Yes

Can Modify Data? Yes No

Can Use in SELECT? No Yes

40. What is Cascading Delete and Cascading Update?

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 10/12
Cascading DELETE: Deleting a record deletes dependent records.
Cascading UPDATE: Updating a primary key updates foreign keys.

sql

FOREIGN KEY (StudentID) REFERENCES Students(StudentID) ON DELETE CASCADE;

Performance Optimization & Indexing


41. What are Clustered and Non-Clustered Indexes?

Clustered Index: Sorts the table itself (1 per table).


Non-Clustered Index: Stores pointers to data.

sql

CREATE CLUSTERED INDEX idx_name ON Employees(Name);


CREATE NONCLUSTERED INDEX idx_salary ON Employees(Salary);

42. What is a B-Tree Index?

A B-Tree index is a balanced tree structure used for indexing in DBMS.

43. How Does Query Optimization Work in DBMS?

Query optimization finds the best execution plan to improve performance.

Example:

Use Indexing
**Avoid SELECT ***
Use Joins efficiently

44. What is the Use of EXPLAIN PLAN in SQL?

`EXPLAIN PLAN` shows how a query will execute.

sql

EXPLAIN ANALYZE SELECT * FROM Employees WHERE Salary > 50000;

Real-World & Scenario-Based Questions


45. How Would You Design a Database for an E-Commerce Application?

1. Tables: `Users`, `Products`, `Orders`, `Payments`.


2. Indexes on frequently searched columns.
3. Use sharding for scalability.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 11/12
46. How Would You Handle Millions of Concurrent Database Requests?

1. Use Load Balancers


2. Implement Caching (Redis, Memcached)
3. Use Read Replicas

47. How Do You Implement Database Backup and Recovery?

1. Full Backup: Entire database.


2. Incremental Backup: Changes since the last backup.
3. Point-In-Time Recovery: Using transaction logs.

bash

mysqldump -u root -p database_name > backup.sql

This completes all 47 DBMS questions with detailed answers and examples. Would you like further
explanations on any specific question? 🚀

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 12/12

You might also like