Basic SQL Questions
- What is the difference between
WHERE
andHAVING
? - Explain the difference between
INNER JOIN
,LEFT JOIN
,RIGHT JOIN
, andFULL OUTER JOIN
. - What is the purpose of a
PRIMARY KEY
and aUNIQUE KEY
? - Explain the concept of
FOREIGN KEY
. - What are
indexes
in SQL? How do they improve performance? - What is a
view
in SQL? What are its advantages and limitations? - How does a
GROUP BY
clause work? Provide an example. - What is the difference between
TRUNCATE
,DELETE
, andDROP
? - What is a subquery? How is it different from a join?
- What are
aggregate functions
in SQL? Give examples.
Intermediate SQL Questions
- Explain the concept of normalization. What are the normal forms?
- What is denormalization? When would you use it?
- How do you use the
CASE
statement in SQL? - What is the difference between
CHAR
andVARCHAR
? - Explain
ACID
properties in the context of SQL databases. - What is the difference between a
clustered index
and anon-clustered index
? - How can you optimize a slow SQL query? Provide strategies.
- What is a
CTE
(Common Table Expression), and how is it different from a subquery? - How do you handle duplicate rows in SQL? Provide examples.
- Explain the
UNION
andUNION ALL
operators.
Advanced SQL Questions
- What are window functions in SQL? Provide examples of
ROW_NUMBER()
,RANK()
, andDENSE_RANK()
. - What is a materialized view? How is it different from a regular view?
- Explain partitioning in SQL. What are the types of partitioning?
- How would you implement pagination in SQL?
- What is the difference between
OLTP
andOLAP
databases? - Explain the concept of a
sharded database
. Why is it used? - How do you detect and resolve deadlocks in SQL databases?
- What is query execution plan? How do you analyze and optimize it?
- Explain the concept of
stored procedures
. How do they differ from functions? - What are triggers in SQL? Provide examples of their use cases.
Real-World Scenarios
- How would you design a database schema for an e-commerce platform?
- How would you migrate a database with zero downtime?
- How do you handle schema changes in a production environment?
- Explain a strategy for backup and restoration in large-scale databases.
- How would you implement database replication for high availability?
- What is the process of indexing a very large table in a live system?
- How would you secure sensitive data in a database (e.g., credit card numbers)?
- How do you optimize queries that involve large datasets (10M+ rows)?
- Explain how you would troubleshoot a query that suddenly started running slow.
- Describe your approach to implementing role-based access control (RBAC) in SQL.
Query-Based Questions
- Write a query to find the second highest salary in an employee table.
- How would you calculate the running total of sales in a table?
- Write a query to find all employees who have the same manager.
- Write a query to delete duplicate rows from a table while keeping one copy.
- How do you find the top 3 customers by revenue?
- Write a query to retrieve the nth row of a table.
- How do you retrieve the first and last records from a table using SQL?
- Write a query to find customers who made purchases in every month of a year.
- Write a query to calculate the percentage contribution of each product to total sales.
- Write a query to find products that have not been sold in the last 30 days.
Performance and Optimization
- What are covering indexes, and how do they improve query performance?
- Explain the use of query hints in SQL.
- How does database partitioning improve query performance?
- What are temp tables, and how are they used?
- How would you handle large data imports into a database without affecting performance?
- Explain batch processing in SQL and its advantages.
- How would you optimize a query with multiple joins?
- What is a correlated subquery? How do you optimize it?
- Explain indexing strategies for composite keys.
- How does indexing affect
INSERT
,UPDATE
, andDELETE
operations?
Data Integrity and Security
- What are the differences between optimistic and pessimistic locking?
- How do you implement auditing in an SQL database?
- What is SQL injection? How do you prevent it?
- What is row-level security in SQL, and how is it implemented?
- How do you enforce data validation rules in SQL databases?
- Explain the difference between soft deletes and hard deletes.
- What is the use of
CHECK
constraints? - How do you encrypt sensitive data in a database?
- What are access control mechanisms in SQL databases?
- How would you implement database masking for sensitive data?
Scalability and High Availability
- What are the challenges of scaling relational databases?
- How do you design a read-replica setup for SQL databases?
- Explain the concept of eventual consistency in distributed databases.
- What is multi-master replication, and when would you use it?
- How do you monitor database performance in a high-traffic environment?
- How would you implement data archiving in SQL databases?
- What is a hot standby? How is it different from a read replica?
- How do you handle database failover?
- What is the role of connection pooling in scalability?
- How do you implement distributed transactions across multiple databases?
Complex Topics
- Explain transaction isolation levels and their use cases.
- What is the difference between a hash join and a nested loop join?
- What is the difference between logical and physical data models?
- How does SQL handle null values in aggregate functions?
- What are the trade-offs of denormalizing data?
- How would you identify and resolve fragmented indexes?
- What are phantom reads, and how do you prevent them?
- Explain the difference between serializable and snapshot isolation.
- What is the purpose of a sequence in SQL?
- How do you implement change data capture (CDC) in SQL databases?
Behavioral and Best Practices
- Describe a challenging SQL problem you solved in your previous project.
- How do you document complex SQL queries for other developers?
- What steps do you take to ensure query maintainability?
- Describe a situation where you optimized a poorly performing query.
- How do you decide between SQL and NoSQL for a project?
- How do you approach designing a schema for a new application?
- How do you ensure database backups are tested regularly?
- Describe a time when you implemented a complex database migration.
- How do you stay updated on SQL and database technologies?
- What tools do you use for monitoring and debugging SQL queries?
Top comments (0)