Welcome to the SQL quiz. This quiz consists of 40 multiple-choice questions to put your understanding of SQL concepts to the test. Each question comes with detailed explanations to help you learn and solidify your SQL expertise. Let's dive in and see how well you know your SQL!
1. SQL stands for?
a) Structured Query Language
b) Sequential Query Language
c) Simple Query Language
d) Solid Quality Language
2. What does the acronym "CRUD" stand for in SQL?
a) Create, Read, Update, Delete
b) Columns, Rows, Update, Drop
c) Concatenate, Retrieve, Union, Drop
d) Copy, Run, Update, Display
3. Which SQL command is used to retrieve data from a database?
a) SEARCH
b) RETRIEVE
c) SELECT
d) FIND
4. What is the purpose of the WHERE clause in SQL?
a) It specifies the columns to be retrieved.
b) It filters the rows returned by the SELECT statement.
c) It orders the results in ascending or descending order.
d) It creates a new table.
5. What is the purpose of the ORDER BY clause in SQL?
a) It filters the rows returned by the SELECT statement.
b) It specifies the columns to be retrieved.
c) It creates a new table.
d) It orders the results in ascending or descending order.
6. Which SQL command is used to insert new data into a database table?
a) ADD
b) INSERT
c) CREATE
d) UPDATE
7. What does the acronym "DDL" stand for in SQL?
a) Data Definition Language
b) Data Deletion Language
c) Data Display Language
d) Data Description Language
8. Which SQL command is used to update existing data in a database table?
a) MODIFY
b) ALTER
c) UPDATE
d) CHANGE
9. What is the purpose of the GROUP BY clause in SQL?
a) It filters the rows returned by the SELECT statement.
b) It groups rows with the same values into summary rows.
c) It orders the results in ascending or descending order.
d) It specifies the columns to be retrieved.
10. What is the purpose of the HAVING clause in SQL?
a) It orders the results in ascending or descending order.
b) It filters the rows returned by the SELECT statement.
c) It specifies the columns to be retrieved.
d) It filters the summary rows created by the GROUP BY clause.
11. What is the purpose of the DISTINCT keyword in SQL?
a) It filters the rows returned by the SELECT statement.
b) It specifies the columns to be retrieved.
c) It removes duplicate rows from the result set.
d) It orders the results in ascending or descending order.
12. What is the purpose of the JOIN clause in SQL?
a) It filters the rows returned by the SELECT statement.
b) It specifies the columns to be retrieved.
c) It combines rows from two or more tables based on a related column.
d) It orders the results in ascending or descending order.
13. Which SQL command is used to delete data from a database table?
a) TRUNCATE
b) DROP
c) REMOVE
d) DELETE
14. What is the purpose of the LIMIT clause in SQL?
a) It filters the rows returned by the SELECT statement.
b) It orders the results in ascending or descending order.
c) It groups rows with the same values into summary rows.
d) It limits the number of rows returned by the SELECT statement.
15. What is the purpose of the BETWEEN operator in SQL?
a) It filters the rows returned by the SELECT statement.
b) It checks if a value exists in a specified list of values.
c) It checks if a value falls within a specified range.
d) It performs a pattern match on a string.
16. What is the purpose of the LIKE operator in SQL?
a) It checks if a value exists in a specified list of values.
b) It filters the rows returned by the SELECT statement.
c) It performs a pattern match on a string.
d) It checks if a value falls within a specified range.
17. What does the COUNT function do in SQL?
a) It counts the total number of rows in a table.
b) It calculates the average value of a column.
c) It retrieves the maximum value in a column.
d) It counts the number of non-null values in a column.
18. What does the SUM function do in SQL?
a) It retrieves the maximum value in a column.
b) It calculates the average value of a column.
c) It counts the total number of rows in a table.
d) It calculates the sum of values in a column.
19. What does the AVG function do in SQL?
a) It calculates the sum of values in a column.
b) It counts the total number of rows in a table.
c) It retrieves the maximum value in a column.
d) It calculates the average value of a column.
20. What does the MAX function do in SQL?
a) It calculates the sum of values in a column.
b) It counts the total number of rows in a table.
c) It retrieves the minimum value in a column.
d) It retrieves the maximum value in a column.
21. What does the MIN function do in SQL?
a) It retrieves the maximum value in a column.
b) It calculates the sum of values in a column.
c) It calculates the average value of a column.
d) It retrieves the minimum value in a column.
22. What is the purpose of the NULL value in SQL?
a) It represents an empty string.
b) It represents a missing or unknown value.
c) It represents the absence of a primary key.
d) It represents a zero value.
23. What is the purpose of the UNION operator in SQL?
a) It combines the results of two or more SELECT statements.
b) It performs a pattern match on a string.
c) It retrieves the maximum value in a column.
d) It filters the rows returned by the SELECT statement.
24. What is the purpose of the INNER JOIN in SQL?
a) It retrieves the maximum value in a column.
b) It combines rows from two or more tables based on a related column.
c) It filters the rows returned by the SELECT statement.
d) It performs a pattern match on a string.
25. What is the purpose of the LEFT JOIN in SQL?
a) It combines rows from two or more tables based on a related column.
b) It retrieves the maximum value in a column.
c) It filters the rows returned by the SELECT statement.
d) It performs a pattern match on a string.
26. Which of the following can be used to create a relationship between two tables?
a) FOREIGN KEY
b) DISTINCT KEY
c) PRIMARY KEY
d) UNIQUE KEY
27. Which of the following can be used to uniquely identify each row of the table?
a) FOREIGN KEY
b) DISTINCT KEY
c) PRIMARY KEY
d) UNIQUE KEY
Quiz on SQL Queries
Let's create a sample database table named "Employees" with columns "ID," "Name," "Age," and "Department." We will also insert some rows of data into the table.-- Creating the Employees table
CREATE TABLE Employees (
ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Department VARCHAR(50)
);
-- Inserting data into the Employees table
INSERT INTO Employees (ID, Name, Age, Department)
VALUES
(1, 'John Doe', 30, 'HR'),
(2, 'Jane Smith', 28, 'Finance'),
(3, 'Michael Johnson', 35, 'IT'),
(4, 'Emily Williams', 32, 'Sales'),
(5, 'Robert Brown', 27, 'Marketing');
28. What SQL query is used to retrieve all columns from the Employees table?
a) SELECT * FROM Employees;
b) SELECT Name, Age, Department FROM Employees;
c) SELECT ID, Name, Age, Department FROM Employees;
d) SELECT Employees;
29. How do you filter the Employees table to show only the rows where the Age is greater than 30?
a) SELECT * FROM Employees WHERE Age > 30;
b) SELECT * FROM Employees HAVING Age > 30;
c) SELECT * FROM Employees WHERE Age >= 30;
d) SELECT * FROM Employees FILTER BY Age > 30;
30. What SQL query is used to count the number of employees in each department?
a) SELECT COUNT() FROM Employees GROUP BY Department;
b) SELECT COUNT() AS TotalEmployees FROM Employees GROUP BY Department;
c) SELECT COUNT(DISTINCT Department) FROM Employees;
d) SELECT COUNT(Department) FROM Employees GROUP BY Department;
31. How do you update the age of an employee with ID 3 to 36 years old?
a) UPDATE Employees SET Age = 36 WHERE ID = 3;
b) UPDATE Employees AGE = 36 WHERE ID = 3;
c) UPDATE Employees VALUES (3, 'Michael Johnson, 36, 'IT');
d) MODIFY Employees SET Age = 36 WHERE ID = 3;
32. How do you delete the employee with ID 5 from the Employees table?
a) DELETE FROM Employees WHERE ID = 5;
b) DELETE * FROM Employees WHERE ID = 5;
c) REMOVE FROM Employees WHERE ID = 5;
d) DROP FROM Employees WHERE ID = 5;
33. How do you retrieve employees with the name 'John Doe' or 'Emily Williams'?
a) SELECT * FROM Employees WHERE Name = 'John Doe' OR 'Emily Williams';
b) SELECT * FROM Employees WHERE Name = 'John Doe' AND 'Emily Williams';
c) SELECT * FROM Employees WHERE Name = 'John Doe', 'Emily Williams';
d) SELECT * FROM Employees WHERE Name IN ('John Doe', 'Emily Williams');
34. What SQL query is used to retrieve the oldest employee's name and age?
a) SELECT Name, Age FROM Employees ORDER BY Age DESC LIMIT 1;
b) SELECT MAX(Age), Name FROM Employees;
c) SELECT TOP 1 Name, Age FROM Employees ORDER BY Age DESC;
d) SELECT Name, Age FROM Employees WHERE Age = MAX(Age);
35. What SQL query is used to retrieve the average age of employees?
a) SELECT AVG(Age) FROM Employees;
b) SELECT AVERAGE(Age) FROM Employees;
c) SELECT SUM(Age)/COUNT(*) FROM Employees;
d) SELECT AGE(AVG) FROM Employees;
36. How do you retrieve the youngest employee's name and age?
a) SELECT Name, Age FROM Employees ORDER BY Age ASC LIMIT 1;
b) SELECT MIN(Age), Name FROM Employees;
c) SELECT LAST(Name), Age FROM Employees ORDER BY Age DESC;
d) SELECT Name, Age FROM Employees WHERE Age = MIN(Age);
Conclusion
Congratulations on completing the SQL quiz! We hope you enjoyed the challenge and learned some new SQL concepts along the way. SQL is a powerful language used for managing and manipulating databases. Keep practicing and experimenting to become an SQL expert! Happy querying!
Comments
Post a Comment
Leave Comment