The document contains a comprehensive list of SQL interview questions categorized into three levels: Basic, Intermediate, and Advanced. It covers fundamental concepts such as SQL statements, keys, joins, and normalization, as well as more complex topics like database design, performance optimization, and handling data anomalies. Each section includes specific questions aimed at assessing knowledge and skills relevant to SQL for freshers and experienced candidates alike.
The document contains a comprehensive list of SQL interview questions categorized into three levels: Basic, Intermediate, and Advanced. It covers fundamental concepts such as SQL statements, keys, joins, and normalization, as well as more complex topics like database design, performance optimization, and handling data anomalies. Each section includes specific questions aimed at assessing knowledge and skills relevant to SQL for freshers and experienced candidates alike.
2. What are the different types of SQL statements? 3. What is a primary key? 4. Explain the difference between primary key and unique key. 5. What is a foreign key? 6. What are joins in SQL? Name different types of joins. 7. What is the difference between INNER JOIN and OUTER JOIN? 8. What is a self join? 9. What is a subquery in SQL? 10.What is the difference between DELETE and TRUNCATE? 11.Explain the difference between CHAR and VARCHAR. 12.What are indexes in SQL? 13.What are constraints in SQL? 14.Explain the concept of normalization. 15.What is denormalization? 16.What are the different normal forms? 17.Explain the difference between a clustered and non-clustered index. 18.What is a stored procedure? 19.What are views in SQL? 20.What is a unique constraint? 21.What is the difference between HAVING and WHERE clauses? 22.What is the difference between UNION and UNION ALL? 23.What is the purpose of the GROUP BY clause? 24.What are aggregate functions? Provide examples. 25.Explain the difference between COUNT(), COUNT(column), and COUNT(*). 26.What is a composite key? 27.Explain the difference between a natural join and a cross join. 28.What is a default constraint in SQL? 29.What is a cursor in SQL? 30.What are the ACID properties of a transaction?
Intermediate SQL Questions (For Experience)
1. What is a common table expression (CTE)?
2. Explain recursive CTE with an example. 3. What is a correlated subquery? 4. Explain the difference between RANK(), DENSE_RANK(), and ROW_NUMBER(). 5. How do you use the CASE statement in SQL? 6. What is the difference between UNION and JOIN? 7. What is a trigger? Explain types of triggers. 8. What are transaction isolation levels? 9. Explain the use of the COALESCE() function. 10.What is a pivot table in SQL? 11.What are window functions? 12.What is the difference between DELETE and DROP? 13.How do you optimize SQL queries for performance? 14.What is the difference between EXISTS and IN? 15.Explain the difference between logical and physical database design. 16.What is the difference between a scalar subquery and a table subquery? 17.What is the WITH clause? 18.How do you create a temporary table? 19.What are derived tables? 20.Explain indexing strategies for performance optimization.
Advanced SQL Scenario-Based Questions
1. Write a query to find the second highest salary of employees.
2. How would you find duplicate records in a table? 3. How do you delete duplicate rows from a table without using a temporary table? 4. Write a query to get the nth highest salary. 5. How do you find the employees who have not placed any orders? 6. Given a table of student marks, write a query to find the top three scorers. 7. Write a query to find the department with the highest number of employees. 8. How would you update a column value based on a condition in another table? 9. Write a query to display records with even row numbers. 10.Write a query to retrieve the last 5 records from a table. 11.How do you find the total salary department-wise? 12.How would you calculate running totals in a result set? 13.Write a query to reverse a string in SQL. 14.How would you swap values of two columns in a single query? 15.Write a query to get the cumulative sum in a result set. 16.Given a table of orders, write a query to find customers with more than five orders. 17.Write a query to find the third last record in a table. 18.How do you find missing numbers in a sequence? 19.How would you find the first non-null value in a list of columns? 20.Write a query to find the most frequently ordered product.
Complex SQL Scenario-Based Questions
1. Explain how to design a database for an online bookstore.
2. Describe steps to normalize a poorly designed table with redundant data. 3. Given a sales table, how do you retrieve monthly sales trends? 4. How would you track changes to a record without losing history? 5. How do you implement a soft delete mechanism? 6. Describe how you would design an audit log table. 7. How would you handle performance issues in a query that uses multiple joins? 8. What is your approach to handling deadlocks? 9. How do you ensure data consistency in a distributed database environment? 10.How would you detect and prevent SQL injection attacks? 11.Given tables for customers and orders, how would you write a query to show customers with no orders in the last year? 12.How would you design a table for storing hierarchical data? 13.Describe how to implement pagination in SQL. 14.Write a query to rank employees based on their salaries. 15.Given a table of logs, write a query to find the first and last entry for each user. 16.How do you find gaps between consecutive dates in a table? 17.How would you design a database for a car rental system? 18.Describe how to handle time zone differences in a global application. 19.How do you optimize a query with nested subqueries? 20.How would you write a query to transpose rows into columns? 21.How do you detect and correct data anomalies in a database? 22.Explain the concept of sharding in databases. 23.How do you handle large data imports efficiently in SQL? 24.How would you use partitioning to improve query performance? 25.Write a query to calculate a moving average. 26.How do you implement referential integrity across multiple databases? 27.What strategies would you use to archive old data? 28.Explain the concept of materialized views and their benefits. 29.Describe how to use a bitmap index. 30.How would you design a solution to store and retrieve versioned records?