Most asked SQL interview questions covering JOINs, indexes, normalization, transactions, and query optimization.
SQL (Structured Query Language) is a standard language for managing and manipulating relational databases. It is used to create, read, update, and delete data in databases like MySQL, PostgreSQL, and SQL Server.
DELETE removes specific rows and can be rolled back. TRUNCATE removes all rows, cannot be rolled back, and is faster. DROP removes the entire table structure including data.
INNER JOIN returns matching rows from both tables. LEFT JOIN returns all rows from left table and matching from right. RIGHT JOIN is opposite. FULL OUTER JOIN returns all rows when there is a match in either table.
A PRIMARY KEY is a column or set of columns that uniquely identifies each row in a table. It cannot contain NULL values and must be unique. Each table can have only one primary key.
A FOREIGN KEY is a column that creates a link between two tables. It references the PRIMARY KEY of another table, enforcing referential integrity.
Normalization is the process of organizing a database to reduce redundancy and improve data integrity. Common forms are 1NF, 2NF, 3NF, and BCNF. Each form has specific rules to eliminate different types of anomalies.
An index is a database structure that improves the speed of data retrieval. It creates a separate data structure pointing to rows in the original table. Indexes speed up SELECT queries but slow down INSERT/UPDATE/DELETE.
WHERE filters rows before grouping and cannot use aggregate functions. HAVING filters groups after GROUP BY and can use aggregate functions like COUNT, SUM, AVG.
A subquery is a query nested inside another query. It can be used in SELECT, FROM, and WHERE clauses. A correlated subquery references columns from the outer query and executes once per row.
Aggregate functions perform calculations on a set of rows: COUNT() counts rows, SUM() adds values, AVG() calculates average, MAX() finds maximum, MIN() finds minimum.
A VIEW is a virtual table based on the result of a SELECT statement. It does not store data itself. Views simplify complex queries, provide security by restricting column access, and present data in a specific format.
A transaction is a sequence of SQL operations executed as a single unit. It follows ACID properties: Atomicity, Consistency, Isolation, Durability. Use BEGIN, COMMIT, and ROLLBACK to control transactions.
Atomicity: all operations succeed or all fail. Consistency: database remains in valid state. Isolation: concurrent transactions do not affect each other. Durability: committed transactions persist even after system failure.
UNION combines results of two SELECT statements and removes duplicates. UNION ALL combines results but keeps all duplicates, making it faster than UNION.
A stored procedure is a precompiled collection of SQL statements stored in the database. It improves performance, reduces network traffic, and allows code reuse. Can accept parameters and return values.
Sign up free to access complete notes — DSA, System Design, HR and more.
🚀 Access Full Notes Free →Build a professional resume to complement your preparation.
Build Free Resume →