🎯 2026 EDITION

SQL Master Top 50 Q&A

Advanced SQL, Database Modeling & Optimization Mastery.

1. SQL Fundamentals
01. What is DBMS?
A Database Management System is software used to manage databases, providing an interface for users to interact with data.
02. Difference between SQL and MySQL?
SQL is a language used to interact with databases. MySQL is an open-source Relational Database Management System that uses SQL.
03. Explain the types of SQL commands (DDL, DML, DCL, TCL).
DDL (Data Definition Language): CREATE, DROP. DML (Data Manipulation Language): INSERT, UPDATE, DELETE. DCL (Data Control Language): GRANT, REVOKE. TCL (Transaction Control Language): COMMIT, ROLLBACK.
04. What is a Primary Key?
A unique identifier for each record in a table. It cannot contain NULL values and must be unique.
05. What is a Foreign Key?
A field in one table that uniquely identifies a row of another table, establishing a link between the two.
06. Explain the difference between CHAR and VARCHAR.
CHAR is a fixed-length string. VARCHAR is a variable-length string. CHAR is faster but consumes more space if the data is shorter than the fixed length.
07. What is a Join?
A clause used to combine rows from two or more tables based on a related column between them.
08. Explain Inner Join vs Left Join.
Inner Join returns only matching records from both tables. Left Join returns all records from the left table and matching records from the right table.
09. What is the difference between TRUNCATE and DELETE?
DELETE is a DML command that removes rows and can be rolled back. TRUNCATE is a DDL command that removes all rows from a table and cannot be rolled back easily (it resets the identity).
10. What are Constraints in SQL?
Rules applied to table columns to limit the type of data (e.g., NOT NULL, UNIQUE, CHECK, DEFAULT).
2. Intermediate SQL
11. What is an Index and why is it used?
An index is a performance-tuning tool that allows the database to find and retrieve data much faster.
12. Explain the difference between Clustered and Non-Clustered Indexes.
A clustered index determines the physical order of data in the table. A non-clustered index is a separate structure from the data rows.
13. What is a View?
A virtual table based on the result set of an SQL statement. It doesn't store data itself.
14. What is a Subquery?
A query nested inside another query (SELECT, INSERT, UPDATE, or DELETE).
15. Difference between UNION and UNION ALL.
UNION removes duplicates; UNION ALL includes them.
16. What is Aggregate Function?
Functions like SUM, AVG, COUNT, MIN, MAX that perform calculations on multiple values and return a single value.
17. Explain GROUP BY and HAVING.
GROUP BY organizes rows into summary rows. HAVING is like WHERE but for groups.
18. What is a Stored Procedure?
A prepared SQL code that you can save and reuse over and over again.
19. What is a Trigger?
A special type of stored procedure that automatically runs when an event (INSERT, UPDATE, DELETE) occurs in the database server.
20. What is a Transaction?
A single unit of work that contains one or more SQL statements. Transactions follow ACID properties.
3. Advanced SQL
21. What are Window Functions?
Functions that perform calculations across a set of table rows related to the current row (e.g., RANK, OVER).
22. What is a Common Table Expression (CTE)?
A temporary result set defined with the 'WITH' clause that can be referenced within a SELECT, INSERT, UPDATE, or DELETE statement.
23. Explain Normalization.
The process of organizing data to minimize redundancy (1NF, 2NF, 3NF).
24. What is Denormalization?
The process of adding redundant data to improve read performance, often used in data warehousing.
25. What is a Self Join?
Joining a table with itself. Useful for hierarchical data.
26. Explain the difference between COALESCE and ISNULL.
COALESCE returns the first non-null expression from a list. ISNULL is a database-specific function to replace NULL with a value.
27. What is a Cursor?
A database object used to retrieve and manipulate data from a result set row by row.
28. Explain the 'MERGE' statement.
Used to perform INSERT, UPDATE, or DELETE operations on a target table based on the results of a join with a source table.
29. What is Database Partitioning?
Dividing a large table into smaller, more manageable pieces (partitions) while keeping a single logical entry point.
30. What is the difference between a Function and a Stored Procedure?
Functions must return a value and cannot have DML statements (usually). Procedures can return multiple values (or none) and can contain DML.
4. Database Design & Modeling
31. What is an E-R Diagram?
Entity-Relationship Diagram. A visual representation of entities and their relationships within a system.
32. Explain 1:1, 1:N, and M:N relationships.
One-to-One, One-to-Many, and Many-to-Many. M:N usually requires a junction table.
33. What is Referential Integrity?
Ensures that relationships between tables remain consistent through foreign key constraints.
34. What is a Data Warehouse?
A central repository of integrated data from one or more disparate sources, used for reporting and data analysis.
35. Explain Star Schema vs Snowflake Schema.
Star Schema is simpler with one fact table and denormalized dimensions. Snowflake Schema normalizes dimension tables.
36. What is ETL?
Extract, Transform, Load. The process of moving data from source systems to a target database.
37. What is Sharding?
Horizontal partitioning of data across multiple database instances to improve scalability.
38. What is a Deadlock?
A situation where two or more transactions are waiting for each other to release locks, causing a permanent block.
39. Explain the difference between a Database and a Schema.
A database is the collection of all data. A schema is a logical container or structural definition within the database.
40. What is NoSQL?
Non-relational databases that provide a mechanism for storage and retrieval of data modeled in means other than tabular relations (e.g., MongoDB, Redis).
5. Practical Scenarios
41. How do you find duplicate rows in a table?
SELECT column, COUNT(*) FROM table GROUP BY column HAVING COUNT(*) > 1.
42. How do you delete duplicate rows?
Using a CTE with ROW_NUMBER() and deleting where the row number is greater than 1.
43. How do you find the nth highest salary?
Using DENSE_RANK() in a subquery or using OFFSET in some SQL dialects.
44. Explain 'EXPLAIN PLAN'.
A tool used to analyze how the database engine executes a query, helping in optimization.
45. What is SQL Injection?
A security vulnerability where an attacker can execute arbitrary SQL code by manipulating input fields. Prevented using parameterized queries.
46. How do you handle NULLs in mathematical operations?
By using COALESCE or ISNULL to replace NULL with 0 before performing the calculation.
47. What is the use of 'LIMIT' and 'OFFSET'?
Used for pagination. LIMIT restricts the number of rows returned; OFFSET skips a specified number of rows.
48. Explain the difference between 'ANY' and 'ALL'.
ANY returns true if any of the subquery values meet the condition. ALL returns true only if all subquery values meet the condition.
49. What is an Upsert?
A combination of Update and Insert. If the record exists, update it; otherwise, insert it.
50. How do you optimize a slow-running query?
Add indexes, avoid 'SELECT *', use joins instead of subqueries where possible, and check the explain plan.
Back to Prep Vault