SQL Online Test - MCQ Questions

Welcome to SQL Online Test!. We will present 25 MCQs (Multiple-Choice Questions) to test your knowledge of SQL (Structured Query Language).

You can select the correct answer for each question and submit the test. You will get your online test score after finishing the complete test.

1. What will the following SQL query return?

SELECT COUNT(*) FROM Employees WHERE Age > 30;
a) The number of employees aged 30 or younger
b) The number of employees aged over 30
c) The list of employees aged over 30
d) The average age of employees over 30

2. What does this SQL statement do?

SELECT Name, Department FROM Employees ORDER BY Department DESC;
a) Retrieves the name and department of all employees in ascending order by department
b) Retrieves the name and department of all employees in descending order by department
c) Deletes employees in descending order by department
d) Updates the department names in descending order

3. Which SQL statement is used to extract data from a database?

a) GET
b) SELECT
c) EXTRACT
d) READ

4. What does the following query calculate?

SELECT AVG(Salary) FROM Employees WHERE Department = 'HR';
a) The total salary for the HR department
b) The highest salary in the HR department
c) The average salary in the HR department
d) The number of employees in the HR department

5. What will the following SQL query return if no matches are found?

SELECT * FROM Employees WHERE Department = 'Legal';
a) An error message
b) A blank result set
c) Zero
d) NULL

6. Which clause is used to filter the records returned by a GROUP BY clause?

a) ORDER BY
b) WHERE
c) HAVING
d) LIMIT

7. What will happen if you try to insert a duplicate value in a column with a UNIQUE constraint?

a) The operation will succeed without any error.
b) The duplicate value will overwrite the existing value.
c) An error will occur.
d) The operation will be ignored without an error.

8. What does the following SQL statement do?

UPDATE Employees SET Salary = Salary * 1.05 WHERE Department = 'Sales';
a) Reduces the salary of all employees in the Sales department by 5%
b) Increases the salary of all employees in the Sales department by 5%
c) Sets the salary of all employees in the Sales department to 5%
d) Multiplies the salary of all employees by 5 in the Sales department

9. How would you select all distinct departments from the Employees table?

a) SELECT Departments FROM Employees;
b) SELECT UNIQUE Department FROM Employees;
c) SELECT DISTINCT Department FROM Employees;
d) SELECT ALL Department FROM Employees;

10. What is the purpose of the LIKE keyword in SQL?

a) To search for a specified pattern in a column
b) To sort the results in a specific order
c) To insert special characters in the database
d) To update data in a specific pattern

11. Which SQL function is used to return the current date and time?

a) DATE()
b) CURRENT_DATE()
c) NOW()
d) TIME()

12. What does the following SQL query return?

SELECT * FROM Employees WHERE FirstName LIKE 'A%';
a) All employees with first names that contain an 'A'
b) All employees with first names that start with 'A'
c) All employees with first names that end with 'A'
d) All employees with 'A' in their first names anywhere

13. What is the result of the following SQL query?

SELECT FirstName, LastName FROM Employees WHERE LastName IS NOT NULL;
a) It selects all employees who do not have a last name.
b) It selects all employees who have a last name.
c) It selects the first names of all employees who have a last name.
d) It selects the last names of all employees only.

14. How do you find the number of rows affected by the last SQL command?

a) GET ROW_COUNT();
b) SELECT ROW_COUNT();
c) CALL ROW_COUNT();
d) ROW_COUNT();

15. Which keyword is used to sort the results in ascending order by default?

a) SORT BY
b) ORDER BY
c) ALIGN BY
d) ARRANGE BY

16. What does the INNER JOIN keyword do in SQL?

a) Joins rows from two tables as long as there is a match between the columns in both tables.
b) Joins all rows from two tables, filling with NULL if there is no match.
c) Returns only the rows from the first table that have a match in the second table.
d) Deletes matched rows between two tables.

17. What is the default constraint in SQL used to ensure that all values in a column are different?

a) UNIQUE
b) DIFFERENT
c) DISTINCT
d) SEPARATE

18. Which command is used to remove a table from the database permanently?

a) REMOVE TABLE
b) DROP TABLE
c) DELETE TABLE
d) ERASE TABLE

19. What is the purpose of the FOREIGN KEY constraint in SQL?

a) To ensure the integrity of the data in one table matches values in another table
b) To prevent duplicate values in the same table
c) To speed up queries using keys
d) To encrypt data using a key

20. What will this SQL statement do?

DELETE FROM Customers WHERE CustomerID = 10;
a) It will delete the 10th record from the Customers table.
b) It will delete the record where the CustomerID is 10 from the Customers table.
c) It will delete all records from the Customers table.
d) It will delete the Customers table entirely.

21. What does the following SQL query return?

SELECT FirstName FROM Employees WHERE LastName = 'Smith' AND FirstName LIKE 'J%';
a) First names of employees with last name 'Smith' and first names starting with 'J'
b) First names of employees with last name 'Smith' or first names starting with 'J'
c) Last names of employees with last name 'Smith' and first names starting with 'J'
d) All employees with last names starting with 'Smith' and first names with 'J'

22. Which SQL keyword is used to remove duplicates from a result set?

a) UNIQUE
b) DISTINCT
c) SINGLE
d) DIFFERENT

23. What does NULL represent in a database?

a) An empty string
b) A zero value
c) A lack of value
d) An error in the database

24. What does the following SQL command do?

TRUNCATE TABLE Employees;
a) Deletes all records in the Employees table without deleting the table
b) Deletes the Employees table from the database
c) Deletes records from the Employees table based on a condition
d) Updates records in the Employees table to NULL

25. What is the function of the ALTER TABLE command in SQL?

a) To delete a table from the database
b) To modify an existing table structure, such as adding a column or changing a column type
c) To rename a table in the database
d) To create a new table in the database

Comments