1. Which SQL statement is used to remove a table from a database?
Step-by-Step Explanation
DROP TABLE is used to completely remove a table and its data from a database. TRUNCATE TABLE removes all rows but keeps the table structure.
Answer: a) DROP TABLE ✅
2. What is the purpose of the COALESCE() function in SQL?
Step-by-Step Explanation
COALESCE() returns the first non-NULL value in a list of arguments, which is useful for handling NULL values.
Answer: c) To return the first non-NULL value in a list. ✅
3. Which SQL clause is used to specify a search condition for groups or aggregates?
Step-by-Step Explanation
HAVING is used to filter groups based on a specified condition, typically after a GROUP BY clause.
Answer: b) HAVING ✅
4. What does the EXISTS operator do in SQL?
Step-by-Step Explanation
The EXISTS operator checks whether a subquery returns any rows.
Answer: d) Tests for the existence of any records in a subquery. ✅
5. Which SQL function is used to convert a value to a specific data type?
Step-by-Step Explanation
Both CAST() and CONVERT() are used to convert a value to a specified data type, although they may have slight syntax differences depending on the SQL dialect.
Answer: a) CAST() ✅
6. What is a VIEW in SQL?
Step-by-Step Explanation
A VIEW is a virtual table that is based on the result-set of an SQL statement. It does not store data itself.
Answer: b) A virtual table based on the result-set of an SQL statement. ✅
7. Which SQL keyword is used to combine the result sets of two or more SELECT statements, removing duplicate rows?
Step-by-Step Explanation
UNION combines the result sets of two or more SELECT statements and removes duplicate rows. UNION ALL includes duplicates.
Answer: d) UNION ✅
8. What is the purpose of a TRANSACTION in SQL?
Step-by-Step Explanation
A transaction ensures that a set of SQL statements are treated as a single unit of work, either all succeed or all fail, maintaining data integrity.
Answer: c) To ensure that a set of SQL statements are treated as a single unit of work. ✅
9. Which SQL function is used to find the largest value in a set of values?
Step-by-Step Explanation
MAX() returns the maximum value in a set of values.
Answer: a) MAX() ✅
10. What is the purpose of a TRIGGER in SQL?
Step-by-Step Explanation
A TRIGGER is a stored procedure that automatically executes in response to certain events in a database, such as INSERT, UPDATE, or DELETE.
Answer: d) To execute a predefined SQL statement in response to certain events in a database. ✅
11. Which SQL operator is used for pattern matching with wildcards?
Step-by-Step Explanation
LIKE is used for pattern matching with wildcards such as % (any sequence of characters) and _ (any single character).
Answer: b) LIKE ✅
12. What does the INNER JOIN clause return in SQL?
Step-by-Step Explanation
INNER JOIN returns only the rows that have matching values in both tables.
Answer: c) Rows with matching values in both tables. ✅
13. Which SQL statement is used to modify the structure of an existing table?
Step-by-Step Explanation
ALTER TABLE is used to add, modify, or delete columns in an existing table.
Answer: a) ALTER TABLE ✅
14. What is the purpose of the CHECK constraint in SQL?
Step-by-Step Explanation
The CHECK constraint is used to ensure that all values in a column satisfy specified conditions.
Answer: d) To limit the value range that can be placed in a column. ✅
15. Which SQL keyword is used to return only unique rows from a query result?
Step-by-Step Explanation
DISTINCT is used to return only unique rows from a query result.
Answer: b) DISTINCT ✅
16. What is the purpose of a STORED PROCEDURE in SQL?
Step-by-Step Explanation
A STORED PROCEDURE is a precompiled set of SQL statements stored in the database that can be executed repeatedly.
Answer: b) To store and execute a precompiled set of SQL statements. ✅
17. Which SQL function is used to calculate the average of a set of values?
Step-by-Step Explanation
AVG() is used to calculate the average of a set of values.
Answer: c) AVG() ✅
18. What does the FULL OUTER JOIN clause return in SQL?
Step-by-Step Explanation
FULL OUTER JOIN returns all rows when there is a match in either the left or right table.
Answer: b) All rows when there is a match in either left or right table. ✅
19. Which SQL operator is used to test if a value is within a range?
Step-by-Step Explanation
BETWEEN is used to test if a value is within a specified range.
Answer: d) BETWEEN ✅
20. What is the primary purpose of an INDEX in SQL?
Step-by-Step Explanation
An INDEX is primarily used to speed up data retrieval operations by allowing the database to quickly locate specific rows.
Answer: b) To speed up data retrieval operations. ✅