0% found this document useful (0 votes)
3 views2 pages

SQL Interview Questions With Theory

The document outlines key SQL concepts including normalization, differences between DELETE, TRUNCATE, and DROP commands, and various index types. It also explains join operations, views, constraints, and aggregate functions with examples. Each section provides essential definitions and SQL syntax relevant for interview preparation.
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)
3 views2 pages

SQL Interview Questions With Theory

The document outlines key SQL concepts including normalization, differences between DELETE, TRUNCATE, and DROP commands, and various index types. It also explains join operations, views, constraints, and aggregate functions with examples. Each section provides essential definitions and SQL syntax relevant for interview preparation.
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/ 2

SQL Interview Questions with Theory and Examples

1. Normalization

Normalization is the process of structuring a relational database to reduce data redundancy and improve data

integrity.

- 1NF: Eliminates repeating groups

- 2NF: Removes partial dependencies

- 3NF: Removes transitive dependencies

2. DELETE vs TRUNCATE vs DROP

- DELETE: Removes selected rows, can be rolled back

- TRUNCATE: Deletes all rows, cannot be rolled back

- DROP: Deletes the entire table structure and data

3. Index Types

- B-Tree Index: Default for range and equality queries

- Bitmap Index: Efficient for columns with low distinct values

- Composite Index: Multi-column index

- Unique Index: Enforces uniqueness

4. Join Example

SELECT e.name, d.department_name FROM employees e JOIN departments d ON e.dept_id = d.id;

5. INNER JOIN vs LEFT JOIN

- INNER JOIN returns only matching rows in both tables

- LEFT JOIN returns all rows from left table, with NULLs for non-matches

6. Subquery vs Correlated Subquery

- Subquery: Independent and runs once

- Correlated Subquery: Depends on outer query and runs per row


SQL Interview Questions with Theory and Examples

7. View

A view is a virtual table based on a query.

Example:

CREATE VIEW high_earners AS SELECT name FROM employees WHERE salary > 100000;

8. Nth Highest Salary

SELECT salary FROM (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk FROM

employees) t WHERE rnk = N;

9. Constraints

- PRIMARY KEY: Unique + NOT NULL

- FOREIGN KEY: Enforces referential integrity

- CHECK: Enforces column-level rules

Example: CHECK (age >= 18 AND salary > 0)

10. Aggregate Functions

Functions that return a single value from a group of rows: SUM(), AVG(), COUNT(), MAX(), MIN()

Example: SELECT department, COUNT(*) FROM employees GROUP BY department;

You might also like