Post content
Top SQL Interview Questions with Answers: Part-2🧠 11. How do you remove duplicate records?🗑️ Use DISTINCT or ROW_NUMBER() with a CTE to delete duplicates. SELECT DISTINCT * FROM table_name; Or:sql WITH Ranked AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY col1, col2 ORDER BY id) AS rn FROM table_name ) DELETE FROM Ranked WHERE rn > 1; 12. What is normalization? Explain its types.🧱 Normalization reduces redundancy and improves data integrity. - 1NF: Atomic columns (no repeating groups) - 2NF: 1NF + no partial dependency - 3NF: 2NF + no transitive dependency - BCNF: Advanced version of 3NF 13. What is denormalization? The process of combining tables to improve read speed by introducing redundancy. Used for reporting and faster queries. ⚡ 14. What is a stored procedure? A saved set of SQL statements that can be reused. 💾 CREATE PROCEDURE GetUsers AS BEGIN SELECT * FROM users; END; 15. What are indexes and why are they used? Indexes speed up query performance by allowing quick data lookup. Useful on columns used in WHERE or JOIN clauses. 🏎️ 16. What is the difference between clustered and non-clustered index? - Clustered: Sorts actual table data. Only one per table. (Physical Order) - Non-clustered: Separate structure that references data. Can have many. (Logical Order) 17. What is a transaction? A group of operations treated as a single unit. It follows ACID principles to maintain data integrity. 18. ACID properties in SQL - Atomicity: All or none of the operations run (All-or-Nothing) - Consistency: Data stays valid before/after transaction ⚖️ - Isolation: Transactions don’t interfere 🧍 - Durability: Changes remain after success ✅ 19. Difference between DELETE, TRUNCATE, and DROP - DELETE: Removes rows, can be rolled back (logged). ⏪ - TRUNCATE: Removes all rows, faster, less logging. 🗑️ - DROP: Deletes table structure and data entirely. 💥 20. What is a NULL value in SQL? NULL represents missing or unknown data. It's different from 0 or an empty string. (Unknown, not Zero.) 💬Double Tap ❤️ For Part-3