mysql Quiz
1. Which SQL keyword is used to retrieve data from a database?
Step-by-Step Explanation
SELECT is the core keyword for retrieving data from one or more tables in a database.
Answer: a) SELECT ✅
2. What is the purpose of the WHERE clause in a SQL statement?
Step-by-Step Explanation
The WHERE clause is used to specify conditions that filter which rows are returned by a query.
Answer: c) To filter the result set. ✅
3. Which SQL keyword is used to sort the result set in ascending order?
Step-by-Step Explanation
ORDER BY ASC is used to sort the result set in ascending order. DESC is for descending order.
Answer: b) ORDER BY ASC ✅
4. What does the JOIN clause do in SQL?
Step-by-Step Explanation
JOIN is used to combine rows from two or more tables based on a related column between them.
Answer: d) Combines rows from two or more tables based on a related column. ✅
5. Which SQL keyword is used to insert new rows into a table?
Step-by-Step Explanation
INSERT is used to add new rows of data to a table.
Answer: a) INSERT ✅
6. What is the purpose of the GROUP BY clause in SQL?
Step-by-Step Explanation
GROUP BY groups rows that have the same values into summary rows, often used with aggregate functions like COUNT(), SUM(), AVG(), etc.
Answer: b) To group rows that have the same values into summary rows. ✅
7. Which SQL keyword is used to modify existing rows in a table?
Step-by-Step Explanation
UPDATE is used to modify existing records in a table.
Answer: d) UPDATE ✅
8. What is the purpose of the PRIMARY KEY constraint in a table?
Step-by-Step Explanation
A PRIMARY KEY uniquely identifies each record in a table and must contain unique values.
Answer: c) To uniquely identify each row in a table. ✅
9. Which SQL keyword is used to delete rows from a table?
Step-by-Step Explanation
DELETE is used to remove rows from a table.
Answer: a) DELETE ✅
10. What does the FOREIGN KEY constraint do in a table?
Step-by-Step Explanation
A FOREIGN KEY is used to link two tables together, referencing the PRIMARY KEY in another table.
Answer: d) Links two tables together. ✅
11. Which SQL aggregate function is used to count the number of rows?
Step-by-Step Explanation
COUNT() is used to count the number of rows in a result set.
Answer: b) COUNT() ✅
12. What is the purpose of the INDEX in a MySQL table?
Step-by-Step Explanation
An INDEX is used to speed up data retrieval operations by allowing the database to quickly locate specific rows.
Answer: c) To improve the speed of data retrieval operations. ✅
13. Which SQL keyword is used to retrieve distinct values from a column?
Step-by-Step Explanation
DISTINCT is used to retrieve only unique or distinct values from a column.
Answer: a) DISTINCT ✅
14. What is the purpose of the AUTO_INCREMENT attribute in a column?
Step-by-Step Explanation
AUTO_INCREMENT automatically generates a unique numeric value for a column, typically used for PRIMARY KEY columns.
Answer: d) To automatically generate a unique numeric value. ✅
15. Which SQL clause is used with aggregate functions to filter groups based on a condition?
Step-by-Step Explanation
HAVING is used with aggregate functions to filter groups based on a condition after the GROUP BY clause.
Answer: b) HAVING ✅
16. What is the purpose of the LIKE operator in SQL?
Step-by-Step Explanation
LIKE is used to compare patterns in strings using wildcard characters like % and _.
Answer: b) To compare patterns in strings. ✅
17. Which SQL data type is used to store variable-length strings?
Step-by-Step Explanation
VARCHAR is used to store variable-length strings, while TEXT is used for longer variable-length strings.
Answer: c) VARCHAR ✅
18. What is the purpose of the TRUNCATE TABLE statement in SQL?
Step-by-Step Explanation
TRUNCATE TABLE removes all rows from a table but does not log the individual row deletions, making it faster than DELETE.
Answer: b) To remove all rows from a table without logging the individual row deletions. ✅
19. Which SQL keyword is used to create a new database?
Step-by-Step Explanation
CREATE DATABASE is used to create a new database.
Answer: d) CREATE DATABASE ✅
20. What is the purpose of a VIEW in MySQL?
Step-by-Step Explanation
A VIEW is a virtual table based on the result-set of an SQL statement. It does not store data itself.
Answer: b) To provide a virtual table based on the result-set of an SQL statement. ✅