PUBLIC QUESTION PREVIEW
Databases & SQL interview questions
SQL queries, indexing, normalization, NoSQL, transactions, query optimization.
Showing 12 of 32 source questions. Sample answers are study material, not employer-specific hiring guidance.
How to work through this preview
Attempt each question before reading its answer. For a concept, give a definition and a concrete example. For code, state constraints, walk through a small input, and check complexity. For design, separate requirements from assumptions and explain failure handling. Use real situations for behavioral answers.
QUESTION 1 / medium / conceptual
What is a database index? How does a B-tree index work? What are the trade-offs of over-indexing?
Sample answer
Hints to guide your next attempt
- Index = separate data structure for fast lookups
- B-tree keeps data sorted and allows binary search
Source tags: index / b-tree / database / query-optimization
QUESTION 2 / easy / conceptual
What are ACID properties in databases? Give a real-world example.
Sample answer
Hints to guide your next attempt
- Bank transfer is the classic example — money must not disappear
Source tags: acid / transactions / database / consistency
QUESTION 3 / easy / coding
Write a SQL query to find the second highest salary from an employee table.
Sample answer
Hints to guide your next attempt
- Use a subquery or LIMIT + OFFSET
- Handle duplicates correctly with DISTINCT
Source tags: sql / subquery / window-functions / rank
QUESTION 4 / easy / conceptual
What is the difference between SQL and NoSQL? When would you choose each?
Sample answer
Hints to guide your next attempt
- Schema flexibility vs. ACID guarantees
- Horizontal vs. vertical scaling
Source tags: sql / nosql / database / scalability / schema
QUESTION 5 / easy / conceptual
Explain all types of JOINs in SQL with examples.
Sample answer
Hints to guide your next attempt
- INNER = intersection, LEFT = all from left + matches, FULL OUTER = union
Source tags: sql / joins / inner-join / left-join / database
QUESTION 6 / medium / conceptual
What is database normalization? Explain 1NF, 2NF, 3NF with examples.
Sample answer
Hints to guide your next attempt
- Each normal form removes a specific type of redundancy
- 3NF: no transitive dependencies
Source tags: normalization / 1nf / 2nf / 3nf / database-design
QUESTION 7 / medium / coding
What are window functions in SQL? Write a query using ROW_NUMBER, RANK, and LAG.
Sample answer
Hints to guide your next attempt
- Window functions operate over a set of rows without collapsing them like GROUP BY
- OVER (PARTITION BY ... ORDER BY ...)
Source tags: sql / window-functions / row-number / rank / lag
QUESTION 8 / medium / conceptual
What are CTEs (Common Table Expressions)? How are they different from subqueries?
Sample answer
Hints to guide your next attempt
- CTE = named temporary result set using WITH clause
- Recursive CTEs can traverse hierarchies
Source tags: sql / cte / with-clause / recursive / subquery
QUESTION 9 / hard / conceptual
What are transaction isolation levels? Explain the problems each level prevents.
Sample answer
Hints to guide your next attempt
- 4 levels: Read Uncommitted, Read Committed, Repeatable Read, Serializable
- Dirty read, non-repeatable read, phantom read
Source tags: transactions / isolation-levels / acid / concurrency / database
QUESTION 10 / medium / conceptual
What is a deadlock in a database? How does it occur and how do you prevent it?
Sample answer
Hints to guide your next attempt
- Two transactions waiting for each other's locks
- Consistent lock ordering prevents deadlocks
Source tags: deadlock / transactions / locking / concurrency / database
QUESTION 11 / easy / coding
Write a SQL query using GROUP BY and HAVING to find departments with average salary above 60,000.
Sample answer
Hints to guide your next attempt
- HAVING filters on aggregated results, WHERE filters on individual rows
Source tags: sql / group-by / having / aggregation / database
QUESTION 12 / medium / conceptual
What is the N+1 query problem? How do you detect and fix it?
Sample answer
Hints to guide your next attempt
- 1 query to get N records, then N queries to fetch related data for each
- Eager loading / JOIN solves it
Source tags: n-plus-1 / orm / query-optimization / performance / database
Check understanding, not recognition
- Can you explain the answer without reading it?
- Can you show when the approach fails or needs a different assumption?
- Can you connect the concept to a real project, task, or decision you have made?
- Can you distinguish a simplified interview example from a production requirement?
A LITTLE MORE CLARITY
Frequently asked questions
How many Databases & SQL questions are shown here?
This public preview shows 12 questions with the supplied answers from the app's 32-question Databases & SQL bank. Full interactive practice requires signing in.
Should I memorize the sample answers?
Use them as reference explanations, not a script or a guarantee of technical correctness for every environment. Explain your assumptions, validate code against your language and version, and discuss trade-offs. Behavioral answers should be built from your own experience.
What do hints and solution steps mean?
Hints identify ideas to consider before reading the answer. When the source question includes steps, they are shown as a separate walkthrough. Example capacities and design targets in a solution are assumptions for that exercise, not real system statistics.
BUILD YOUR NEXT OPPORTUNITY
Practice Databases & SQL actively.
Sign in to use the full topic bank and interactive practice workspace.