BASIC SQL INTERVIEW QUESTIONS (1–50)
1. What is SQL?
Answer: SQL stands for Structured Query Language used to manage and query databases.
2. What is a database?
Answer: A database is an organized collection of data stored electronically.
3. What is a table in SQL?
Answer: A table is a collection of related data in rows and columns.
4. What is a record?
Answer: A record is a single row in a table representing one item of data.
5. What is a field?
Answer: A field is a column in a table that holds a specific type of data.
6. What is a primary key?
Answer: A column that uniquely identifies each record in a table.
7. What is a foreign key?
Answer: A column that links two tables by referencing another table’s primary key.
8. What is a unique key?
Answer: Ensures all values in a column are unique but allows one NULL value.
9. What is a NULL value?
Answer: Represents missing or unknown data.
10. Difference between DELETE and TRUNCATE?
Answer: DELETE removes specific rows; TRUNCATE removes all rows quickly.
11. What is DDL?
Answer: Data Definition Language, used to define structures (CREATE, ALTER, DROP).
12. What is DML?
Answer: Data Manipulation Language (INSERT, UPDATE, DELETE).
13. What is DCL?
Answer: Data Control Language (GRANT, REVOKE).
14. What is TCL?
Answer: Transaction Control Language (COMMIT, ROLLBACK, SAVEPOINT).
15. What is normalization?
Answer: Organizing data to remove redundancy.
16. What is denormalization?
Answer: Combining tables for faster queries.
17. What is a join?
Answer: Combines data from multiple tables.
18. Types of joins?
Answer: INNER, LEFT, RIGHT, FULL, CROSS.
19. What is INNER JOIN?
Answer: Returns rows with matching values in both tables.
20. What is LEFT JOIN?
Answer: Returns all rows from the left table and matching ones from the right.
21. What is RIGHT JOIN?
Answer: Returns all rows from the right table and matching ones from the left.
22. What is FULL JOIN?
Answer: Returns all rows from both tables whether matched or not.
23. What is CROSS JOIN?
Answer: Produces a Cartesian product of both tables.
24. What is a constraint?
Answer: A rule that enforces data integrity.
25. Examples of constraints?
Answer: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT.
26. What is a view?
Answer: A virtual table based on a query result.
27. What is an index?
Answer: Improves query speed by allowing faster lookups.
28. What is a subquery?
Answer: A query inside another query.
29. What is a correlated subquery?
Answer: A subquery that depends on the outer query.
30. What is a stored procedure?
Answer: A saved SQL code that can be reused.
31. What is a trigger?
Answer: Automatically executes when a specific event occurs.
32. What is a cursor?
Answer: Used to fetch rows one by one from a query result.
33. What is a schema?
Answer: Logical structure of the database (tables, views, etc.).
34. What is the SELECT statement used for?
Answer: To retrieve data from a table.
35. What does DISTINCT do?
Answer: Removes duplicate values from results.
36. What is the WHERE clause used for?
Answer: Filters rows before grouping.
37. What is the HAVING clause used for?
Answer: Filters results after grouping.
38. What is the ORDER BY clause?
Answer: Sorts query results.
39. What is GROUP BY?
Answer: Groups rows with the same values.
40. What is LIMIT or TOP?
Answer: Restricts the number of returned rows.
41. What are aggregate functions?
Answer: COUNT, SUM, AVG, MIN, MAX.
42. What is BETWEEN used for?
Answer: Filters results within a range.
43. What is LIKE used for?
Answer: Performs pattern matching in strings.
44. What is IN used for?
Answer: Filters rows that match any value in a list.
45. What is the difference between CHAR and VARCHAR?
Answer: CHAR is fixed-length; VARCHAR is variable-length.
46. What is the CASE statement?
Answer: Implements conditional logic in SQL.
47. What is an alias?
Answer: A temporary name for a table or column.
48. What is the DEFAULT constraint?
Answer: Assigns a default value when no value is provided.
49. What is a composite key?
Answer: A key formed by combining two or more columns.
50. What is a transaction?
Answer: A sequence of SQL operations performed as a single unit.
INTERMEDIATE SQL INTERVIEW QUESTIONS (51–100)
51. What are ACID properties?
Answer: Atomicity, Consistency, Isolation, Durability.
52. What is the difference between UNION and UNION ALL?
Answer: UNION removes duplicates; UNION ALL includes them.
53. What is a self join?
Answer: A table joined with itself.
54. What is a temporary table?
Answer: A table that exists temporarily during a session.
55. What is a common table expression (CTE)?
Answer: A temporary result set defined using WITH.
56. What is a scalar function?
Answer: Returns a single value.
57. What is a user-defined function (UDF)?
Answer: Custom function created by users.
58. Difference between RANK() and DENSE_RANK()?
Answer: RANK() skips ranks; DENSE_RANK() doesn’t.
59. What is ROW_NUMBER()?
Answer: Assigns a unique sequential number to each row.
60. What is a window function?
Answer: Performs calculations across related rows.
61. What is COALESCE()?
Answer: Returns the first non-null value.
62. What is the difference between ISNULL() and COALESCE()?
Answer: ISNULL handles two arguments; COALESCE handles multiple.
63. What is EXISTS?
Answer: Tests if a subquery returns rows.
64. What is ANY and ALL?
Answer: Compare a value to a set of values returned by a subquery.
65. What is a sequence?
Answer: Generates sequential numeric values.
66. What is the difference between DELETE and DROP?
Answer: DELETE removes data; DROP removes the table structure.
67. What is a materialized view?
Answer: A view that stores the query result physically.
68. What is a checkpoint?
Answer: Saves all changes permanently to disk.
69. What is rollback?
Answer: Undo changes of a transaction.
70. What is commit?
Answer: Saves all transaction changes permanently.
71. What is savepoint?
Answer: Marks a point to which you can roll back.
72. What is the difference between clustered and non-clustered index?
Answer: Clustered sorts data physically; non-clustered creates a separate structure.
73. What is referential integrity?
Answer: Ensures relationships between tables remain consistent.
74. What is cascading delete/update?
Answer: Automatically updates or deletes related rows.
75. What is data integrity?
Answer: Accuracy and consistency of data.
76. What is a surrogate key?
Answer: An artificial unique identifier, often numeric.
77. What is an execution plan?
Answer: Shows how SQL Server executes a query.
78. What is query optimization?
Answer: Improving performance by rewriting queries or adding indexes.
79. What is partitioning?
Answer: Dividing a large table into smaller pieces.
80. What is sharding?
Answer: Horizontal partitioning across multiple servers.
81. What is a synonym in SQL?
Answer: Alias for another object like a table or view.
82. What is a sequence generator?
Answer: Generates unique sequential numbers.
83. What are system functions?
Answer: Built-in functions provided by SQL engine.
84. What is NVL()?
Answer: Replaces NULL with a given value (Oracle).
85. What is the difference between DELETE and TRUNCATE in transaction logs?
Answer: DELETE logs each row; TRUNCATE logs only table deallocation.
86. What is a deadlock?
Answer: Two processes waiting on each other’s locks indefinitely.
87. How to avoid deadlocks?
Answer: Access tables in the same order, use shorter transactions.
88. What is an orphan record?
Answer: A child record without a corresponding parent.
89. What is SQL injection?
Answer: A security attack injecting malicious SQL code.
90. How to prevent SQL injection?
Answer: Use parameterized queries or stored procedures.
91. What is a scalar subquery?
Answer: Returns a single value.
92. What is a correlated subquery?
Answer: References a column from the outer query.
93. What is a recursive CTE?
Answer: A CTE that refers to itself for hierarchical queries.
94. What is a lateral join?
Answer: Allows a subquery to reference columns from preceding tables.
95. What is metadata?
Answer: Data that describes other data.
96. What is an optimizer hint?
Answer: Suggests how the database should execute a query.
97. What is query caching?
Answer: Stores query results for faster reuse.
98. What is an execution plan cost?
Answer: A measure of query performance.
99. What is batch processing?
Answer: Running a group of SQL statements together.
100. What is real-time processing?
Answer: Immediate execution and response of SQL operations.
ADVANCED SQL INTERVIEW QUESTIONS (101–150)
101. What are window functions used for?
Answer: Performing aggregate calculations over partitions of data.
102. What is ROW_NUMBER() used for?
Answer: Assigns unique sequential numbers to rows.
103. Difference between OLTP and OLAP?
Answer: OLTP is for transactions; OLAP is for analysis.
104. What is data warehousing?
Answer: Central repository for integrated data from multiple sources.
105. What is ETL?
Answer: Extract, Transform, Load process in data warehousing.
106. What is pivoting in SQL?
Answer: Rotating data from rows into columns.
107. What is unpivoting?
Answer: Converting columns into rows.
108. What is dynamic SQL?
Answer: SQL code built and executed at runtime.
109. What is a recursive query?
Answer: A query that references itself for hierarchical data.
110. What is hierarchical data?
Answer: Data with parent-child relationships.
111. What is JSON support in SQL?
Answer: Storing and querying JSON data in databases.
112. What is XML data type?
Answer: Stores structured XML data within a table.
113. What is full-text search?
Answer: Searching text data efficiently using indexes.
114. What is a collation?
Answer: Defines rules for string comparison and sorting.
115. What is query parallelism?
Answer: Executing parts of a query simultaneously on multiple CPUs.
116. What is indexing strategy?
Answer: Planning how indexes are applied for optimal performance.
117. What is query tuning?
Answer: Modifying queries to improve performance.
118. What is plan caching?
Answer: Reusing stored execution plans for repeated queries.
119. What are temporary views?
Answer: Views created for session-level use.
120. What is partition pruning?
Answer: Skipping partitions that don’t meet query conditions.
121. What is the difference between primary and candidate keys?
Answer: Candidate keys are potential primary keys.
122. What are check constraints?
Answer: Ensure data meets specific conditions.
123. What is a surrogate key example?
Answer: Auto-increment ID in a table.
124. What is an identity column?
Answer: Automatically generates sequential numbers for each row.
125. What is a trigger used for?
Answer: Automating tasks like auditing or validation.
126. What are stored procedures used for?
Answer: Reusable logic and performance optimization.
127. What is an execution context?
Answer: The environment in which SQL code runs.
128. What is a transaction log?
Answer: Records all database modifications.
129. What is SQL profiling?
Answer: Monitoring SQL performance metrics.
130. What is data migration?
Answer: Moving data from one system to another.
131. What is CDC (Change Data Capture)?
Answer: Tracks changes in data for replication or auditing.
132. What is replication?
Answer: Copying data from one database to another.
133. What is mirroring?
Answer: Maintaining a duplicate database for high availability.
134. What is clustering?
Answer: Grouping servers for load balancing and failover.
135. What is sharding vs partitioning?
Answer: Sharding splits data across servers; partitioning splits within one.
136. What is schema binding?
Answer: Prevents changes to underlying objects used by a view.
137. What are transactions isolation levels?
Answer: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE.
138. What is dirty read?
Answer: Reading uncommitted data from another transaction.
139. What is phantom read?
Answer: Rows appear or disappear between queries in a transaction.
140. What is non-repeatable read?
Answer: Same row gives different values within one transaction.
141. What is query hinting?
Answer: Forcing specific optimizer behavior.
142. What is indexing fragmentation?
Answer: Physical disorder of index pages reducing performance.
143. What is query plan recompilation?
Answer: Regeneration of plan due to data or structure change.
144. What is parameter sniffing?
Answer: SQL Server uses cached plans not optimal for new parameters.
145. What is database locking?
Answer: Prevents concurrent transactions from conflicting.
146. What is deadlock detection?
Answer: Process of identifying and resolving deadlocks.
147. What is a backup strategy?
Answer: Regular full, differential, and log backups.
148. What is point-in-time recovery?
Answer: Restoring a database to a specific moment.
149. What is database auditing?
Answer: Tracking and logging database activities.
150. What are best practices for SQL performance?
Answer: Use indexes, avoid SELECT *, optimize joins, and limit data retrieval.
Thanks for reading this post! I hope you found it helpful. Feel free to share it with others or your teammates so they can benefit from it too.Â
![]()