SQL Advanced Interview Preparation
Level Type
Advanced
1. How to optimize a slow query?
➤ Use indexing, avoid SELECT *, use WHERE clauses properly.
2. What is indexing and its types?
➤ Single column index, Composite index, Unique index, Full-text index.
3. What is a partitioned table?
➤ A table divided into multiple pieces for better management and performance.
4. How does indexing impact INSERT and UPDATE?
➤ Indexing can slow down INSERT and UPDATE due to additional overhead.
5. Explain CTE (Common Table Expressions)?
➤ Temporary result set that can be referenced within a query.
6. What is window function in SQL?
➤ Functions like ROW_NUMBER(), RANK(), used across a set of rows related to the current row.
7. What is replication in SQL?
➤ Copying data from one database to another automatically.
8. Difference between clustered and non-clustered index?
➤ Clustered index sorts data physically; non-clustered uses a separate structure.
9. How to handle deadlocks in SQL?
➤ Minimize locks, set timeout, access tables in same order.
10. What are materialized views?
➤ Views that store the result physically like a table.
11. Explain normalization forms (1NF, 2NF, 3NF)?
➤ Steps to organize data into relational tables.
12. What is sharding in databases?
➤ Distributing data across multiple databases.
13. What is the difference between DELETE, TRUNCATE, and DROP?
➤ DELETE removes rows, TRUNCATE removes all rows fast, DROP removes entire table.
14. How to find nth highest salary in SQL?
➤ Using subquery and ORDER BY with LIMIT.
15. What are SQL injection attacks?
➤ Attacks that insert malicious SQL code into queries.
16. How can you enforce data integrity in SQL?
➤ Using constraints like PRIMARY KEY, FOREIGN KEY, CHECK, UNIQUE.
17. What are transactions isolation levels?
➤ READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE.
18. What is two-phase commit?
➤ A protocol that ensures all databases in a distributed system agree to commit or rollback.
19. What is a surrogate key?
➤ An artificial key (like auto-incremented id) instead of a real-world key.
20. How to calculate running totals in SQL?
➤ Using SUM() OVER (ORDER BY column_name).
Comments
Post a Comment