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

Database notes for interview

The document provides a comprehensive overview of essential database interview topics, including definitions and differences between DBMS and RDBMS, SQL commands, normalization, and ACID properties. It also covers key concepts such as primary and foreign keys, types of joins, indexes, views, stored procedures, and triggers. Additionally, it explains normalization forms and their goals, along with practical examples and SQL syntax for creating indexes.

Uploaded by

Khaledun Nahar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Database notes for interview

The document provides a comprehensive overview of essential database interview topics, including definitions and differences between DBMS and RDBMS, SQL commands, normalization, and ACID properties. It also covers key concepts such as primary and foreign keys, types of joins, indexes, views, stored procedures, and triggers. Additionally, it explains normalization forms and their goals, along with practical examples and SQL syntax for creating indexes.

Uploaded by

Khaledun Nahar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

✅ Complete List of Important Database Interview Topics

No. Topic Quick Summary


1 What is DBMS? A software for storing, retrieving, and managing data.
2 What is RDBMS? A DBMS based on relational models (tables).
3 SQL vs NoSQL SQL: Structured, tabular; NoSQL: Unstructured or semi-structured.
4 Primary Key vs Foreign Key Primary Key uniquely identifies a row. Foreign Key links tables.
5 Normalization Process to reduce redundancy and improve data integrity.
6 Denormalization Adding redundancy for faster data access.
7 ER Diagram Visual representation of entities and their relationships.
INNER, LEFT, RIGHT, FULL OUTER JOIN — used to combine
8 Types of Joins
rows from two or more tables.
9 Indexes Speed up data retrieval but may slow down writes.
10 Views Virtual tables based on SQL queries.
11 Stored Procedures Precompiled SQL code to perform a task.
12 Triggers SQL code that auto-executes on certain DB events.
13 Transactions A group of SQL operations that are executed together.
Atomicity, Consistency, Isolation, Durability — properties of a
14 ACID Properties
transaction.
15 Normalization Forms (1NF - 5NF) Rules to organize DB properly. 3NF is most commonly used.
16 Schema vs Instance Schema: DB design; Instance: current DB state.
17 Constraints Rules applied to data in tables (e.g., NOT NULL, UNIQUE).
Difference Between DELETE, DELETE = remove rows; TRUNCATE = faster delete; DROP =
18
TRUNCATE, DROP delete table.
19 Union vs Union All UNION removes duplicates; UNION ALL keeps them.
20 Keys (Candidate, Super, Alternate) Used to uniquely identify records.

1. What is a Database?

Answer:
A database is an organized collection of data that can be easily accessed, managed, and
updated. Databases are used to store information electronically and are managed by
Database Management Systems (DBMS), such as MySQL, Oracle, SQL Server, and
PostgreSQL.

2. What is the difference between DBMS and RDBMS?

Answer:

Feature DBMS RDBMS


Data Storage File system Tables (rows and columns)
Relationships No Yes (via primary/foreign keys)
Examples Microsoft Access, XML DB MySQL, PostgreSQL, Oracle
Normalization Not supported Supported

3. What is SQL?

Answer:
SQL (Structured Query Language) is a standard programming language used to manage and
manipulate relational databases. It is used for querying, inserting, updating, and deleting
data.

4. What are the different types of SQL commands?

Answer:

 DDL (Data Definition Language): CREATE, ALTER, DROP

 DML (Data Manipulation Language): INSERT, UPDATE, DELETE

 DCL (Data Control Language): GRANT, REVOKE

 TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT

 DQL (Data Query Language): SELECT

5. What is a Primary Key?

Answer:
A Primary Key uniquely identifies each record in a table. It must contain unique values and cannot be NULL.
Each table can have only one primary key.

6. What is a Foreign Key?

Answer:
A Foreign Key is a field in a table that creates a relationship between two tables. It refers to the Primary Key of
another table and helps maintain referential integrity.

7. What is Normalization?

Answer:
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity.
Common normal forms include:

 1NF: Eliminate repeating groups


 2NF: Remove partial dependencies
 3NF: Remove transitive dependencies

8. What is a JOIN? Name its types.

Answer:
A JOIN clause is used to combine rows from two or more tables based on a related column. Types of JOINs:

 INNER JOIN: Returns matching rows from both tables


 LEFT JOIN: All rows from the left table + matching from the right
 RIGHT JOIN: All rows from the right table + matching from the left
 FULL JOIN: All rows when there is a match in either table
 SELF JOIN: Joins a table with itself

9. What is an Index?

Answer:
An Index improves the speed of data retrieval in a database. It is similar to an index in a book and helps the
DBMS find rows more efficiently.

10. What is a View?

Answer:
A View is a virtual table based on the result set of an SQL statement. It does not store the data itself but provides a
way to look at data from one or more tables.

11. What is ACID in databases?

Answer:
ACID properties ensure reliable processing of database transactions:

 Atomicity: All-or-nothing rule


 Consistency: Data must be valid after transaction
 Isolation: Transactions do not interfere with each other
 Durability: Changes persist after completion

12. Difference between DELETE, TRUNCATE, and DROP?

Answer:

Command Deletes Data Rollback Possible Affects Structure


DELETE Yes Yes No
TRUNCATE Yes (All) No No
DROP Yes (All) No Yes (table removed)

13. What is a stored procedure?

Answer:
A Stored Procedure is a precompiled collection of SQL statements that can be executed repeatedly. It helps in code
reusability and improves performance.

14. What is a trigger in SQL?


Answer:
A Trigger is a set of actions that are automatically executed in response to certain events on a table, such as
INSERT, UPDATE, or DELETE.

15. What is the difference between WHERE and HAVING clause?

Answer:

 WHERE: Used to filter rows before grouping


 HAVING: Used to filter groups after applying GROUP BY

SQL Indexing - Interview Cheat Sheet


🔹 An Index improves the speed of data retrieval in a database. It works like an index in a
book to locate data efficiently without scanning every row.

📘 Example Table: Employees


EmployeeID Name Department Salary

101 Alice Smith HR 60000

102 Bob Johnson IT 75000

103 Carol White Finance 70000

104 David Black IT 80000

105 Emma Brown HR 65000

⚙️Creating an Index on the 'Department' Column


SQL Syntax:

CREATE INDEX idx_department ON Employees(Department);

🔍 How It Helps
Query: SELECT * FROM Employees WHERE Department = 'IT';

Without an index, the DBMS performs a full table scan.


With the index, the DBMS jumps directly to the relevant rows.

📊 Internal View of Indexing (Simplified)


Department (Indexed) Row Reference
Finance Row 3

HR Row 1, Row 5

IT Row 2, Row 4

✅ When to Use Indexes


- Columns frequently used in WHERE, JOIN, ORDER BY, or GROUP BY

- Large tables where fast data lookup is needed

❌ Caution
- Indexes increase storage requirements

- Too many indexes can slow down INSERT/UPDATE/DELETE operations

🔍 What is Normalization?
Normalization is the process of organizing data in a database to reduce redundancy and
improve data integrity. It involves dividing large tables into smaller ones and defining
relationships between them.

✅ Goals of Normalization
Eliminate redundant data (repetition of data).

Ensure data dependencies make sense.

Make the database more efficient.

🧱 Normal Forms (NF)


1NF – First Normal Form
Atomic (indivisible) values in each column.

No repeating groups.

Example:
StudentID Name Courses
1 Alice Math, Physics
2 Bob Chemistry
👉 Not in 1NF (multi-valued attribute Courses)

Converted to 1NF:

StudentID Name Course


1 Alice Math
1 Alice Physics
2 Bob Chemistry

2NF – Second Normal Form


 In 1NF.

 No partial dependency (non-prime attribute depends only on part of a composite


primary key).
Example (Before 2NF):

StudentID Course Instructor


1 Math Mr. Rahim
1 Physics Mr. Karim
👉 If the primary key is (StudentID, Course), then Instructor depends only on Course, not full
key → Partial Dependency

Split to 2NF:

Student_Course Table:

StudentID Course
1 Math
1 Physics
Course_Instructor Table:

Course Instructor
Math Mr. Rahim
Physics Mr. Karim

3NF – Third Normal Form


In 2NF.

No transitive dependency (non-prime attribute depends on another non-prime attribute).

Example (Before 3NF):

StudentID Name Department Dept_Location


1 Alice CS Building A
2 Bob Math Building B
👉 Dept_Location depends on Department, not on StudentID → Transitive Dependency

Split to 3NF:

Student Table:

StudentID Name Department


1 Alice CS
2 Bob Math

Department Table:

Department Dept_Location
CS Building A
Math Building B

You might also like