Frequently asked questions and answers of SQL in Programming Technologies of Computer Science to enhance your skills, knowledge on the selected topic. We have compiled the best SQL Interview question and answer, trivia quiz, mcq questions, viva question, quizzes to prepare. Download SQL FAQs in PDF form online for academic course, jobs preparations and for certification exams .
Intervew Quizz is an online portal with frequently asked interview, viva and trivia questions and answers on various subjects, topics of kids, school, engineering students, medical aspirants, business management academics and software professionals.
Question-1. What is SQL?
Answer-1: SQL (Structured Query Language) is a standard language used for managing and manipulating relational databases.
Question-2. What are the different types of SQL statements?
Answer-2: SQL statements are categorized as DDL, DML, DCL, and TCL.
Question-3. What is the difference between DELETE and TRUNCATE?
Answer-3: DELETE removes rows selectively and can be rolled back. TRUNCATE removes all rows and cannot be rolled back.
Question-4. What are the primary keys in SQL?
Answer-4: A primary key uniquely identifies each row in a table and does not allow null values.
Question-5. What is a foreign key in SQL?
Answer-5: A foreign key is a column that establishes a relationship between two tables by referencing a primary key in another table.
Question-6. What is the difference between WHERE and HAVING?
Answer-6: WHERE filters rows before grouping; HAVING filters after grouping.
Question-7. What is a join in SQL?
Answer-7: A join combines rows from two or more tables based on a related column.
Question-8. What are the different types of joins in SQL?
Answer-8: Types include INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, and CROSS JOIN.
Question-9. What is the difference between INNER JOIN and OUTER JOIN?
Answer-9: INNER JOIN returns matching rows; OUTER JOIN returns all rows, with nulls for unmatched rows.
Question-10. What is normalization in SQL?
Answer-10: Normalization organizes data to reduce redundancy and improve integrity through normal forms.
Question-11. What are the normal forms in database design?
Answer-11: Normal forms include 1NF, 2NF, 3NF, BCNF, and higher forms, each with stricter rules to remove redundancy.
Question-12. What is a unique key in SQL?
Answer-12: A unique key ensures all values in a column or combination of columns are unique, but allows one null value.
Question-13. What is the difference between CHAR and VARCHAR?
Answer-13: CHAR is fixed-length, while VARCHAR is variable-length, using only as much space as needed.
Question-14. What is an index in SQL?
Answer-14: An index improves query performance by allowing faster data retrieval.
Question-15. What are the types of indexes in SQL?
Answer-15: Types include clustered, non-clustered, unique, and full-text indexes.
Question-16. What is a view in SQL?
Answer-16: A view is a virtual table based on the result of an SQL query, used for abstraction and security.
Question-17. Can you update data in a view?
Answer-17: Yes, if the view is created from a single table without aggregations or complex joins.
Question-18. What is a stored procedure in SQL?
Answer-18: A stored procedure is a precompiled set of SQL statements that can be executed with parameters.
Question-19. What is a trigger in SQL?
Answer-19: A trigger is a stored procedure that automatically executes in response to specific database events.
Question-20. What is a cursor in SQL?
Answer-20: A cursor is a database object used to retrieve, manipulate, and iterate through query results row by row.
Question-21. What is a subquery in SQL?
Answer-21: A subquery is a query nested inside another query to perform intermediate calculations or filters.
Question-22. What is the difference between a correlated and non-correlated subquery?
Answer-22: A correlated subquery depends on the outer query, while a non-correlated subquery is independent.
Question-23. What is the purpose of the GROUP BY clause in SQL?
Answer-23: GROUP BY groups rows with the same values into summary rows, often used with aggregate functions.
Question-24. What are aggregate functions in SQL?
Answer-24: Aggregate functions perform calculations on multiple rows, e.g., SUM, AVG, COUNT, MIN, MAX.
Question-25. What is the ORDER BY clause in SQL?
Answer-25: ORDER BY sorts query results in ascending (ASC) or descending (DESC) order.
Question-26. What is the LIMIT clause in SQL?
Answer-26: LIMIT restricts the number of rows returned by a query, supported by most databases.
Question-27. What is the difference between UNION and UNION ALL?
Answer-27: UNION removes duplicate rows, while UNION ALL includes duplicates.
Question-28. What is a transaction in SQL?
Answer-28: A transaction is a sequence of operations performed as a single logical unit of work.
Question-29. What are the ACID properties in SQL?
Answer-29: ACID ensures database reliability through Atomicity, Consistency, Isolation, and Durability.
Question-30. What is the ROLLBACK statement in SQL?
Answer-30: ROLLBACK undoes changes made by a transaction if it hasn't been committed.
Question-31. What is the COMMIT statement in SQL?
Answer-31: COMMIT saves changes made by a transaction permanently.
Question-32. What is the purpose of the SAVEPOINT statement in SQL?
Answer-32: SAVEPOINT sets a point in a transaction to which you can later roll back.
Question-33. What is a data warehouse?
Answer-33: A data warehouse is a centralized repository for storing and analyzing large amounts of data.
Question-34. What is the difference between OLTP and OLAP?
Answer-34: OLTP is for transaction processing; OLAP is for analytical querying and reporting.
Question-35. What is a primary difference between DROP and DELETE?
Answer-35: DROP removes the table entirely; DELETE removes data but retains the table structure.
Question-36. What is the CASE statement in SQL?
Answer-36: CASE is used for conditional logic within SQL queries.
Question-37. What is SQL injection?
Answer-37: SQL injection is a security vulnerability where attackers manipulate SQL queries to access data.
Question-38. How can you prevent SQL injection?
Answer-38: Use parameterized queries, stored procedures, and input validation to prevent SQL injection.
Question-39. What is the difference between RANK, DENSE_RANK, and ROW_NUMBER?
Answer-39: RANK allows gaps, DENSE_RANK avoids gaps, and ROW_NUMBER assigns unique sequential numbers.
Question-40. What is a TEMP table in SQL?
Answer-40: A TEMP table stores data temporarily for the duration of a session or transaction.
Question-41. What is a self-join in SQL?
Answer-41: A self-join joins a table to itself to compare rows within the same table.
Question-42. What is a common table expression (CTE)?
Answer-42: A CTE is a temporary result set defined within a query using the WITH keyword.
Question-43. What is a materialized view?
Answer-43: A materialized view is a precomputed, stored query result that improves performance for complex queries.
Question-44. What is the NULL value in SQL?
Answer-44: NULL represents a missing or undefined value in a database column.
Question-45. What is the difference between IS NULL and = NULL?
Answer-45: IS NULL checks for null values; = NULL is invalid because null is not equal to anything.
Question-46. How do you optimize SQL queries?
Answer-46: Optimize queries by indexing, avoiding SELECT *, and analyzing execution plans.
Question-47. What is the EXPLAIN or EXPLAIN PLAN statement?
Answer-47: It provides the execution plan of a query, helping identify performance bottlenecks.
Question-48. What are window functions in SQL?
Answer-48: Window functions perform calculations across a set of rows related to the current row. Examples: OVER, RANK.
Question-49. What is the difference between FULL OUTER JOIN and CROSS JOIN?
Answer-49: FULL OUTER JOIN includes all rows with nulls for unmatched rows; CROSS JOIN creates a Cartesian product.
Question-50. How do you enforce referential integrity in SQL?
Answer-50: Use foreign keys with ON DELETE or ON UPDATE constraints to enforce referential integrity.
Frequently Asked Question and Answer on SQL
SQL Interview Questions and Answers in PDF form Online
SQL Questions with Answers
SQL Trivia MCQ Quiz