Site icon i2tutorials

MySQL-Quiz

This Quiz contains totally 25 Questions each carry 1 point for you.


  1. Which SQL command is used to remove a table from a database in MySQL?

DROP TABLE
DELETE TABLE
REMOVE TABLE
TRUNCATE TABLE

Correct!

Wrong!

2. Which type of JOIN returns only the rows that have matching values in both tables being joined?
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL JOIN

Correct!

Wrong!

3. Which aggregate function returns the total sum of a numeric column?
AVG()
COUNT()
SUM()
MAX()

Correct!

Wrong!

4. Which constraint ensures that all values in a column are different?
PRIMARY KEY
UNIQUE
NOT NULL
FOREIGN KEY

Correct!

Wrong!

5. Which constraint automatically generates a unique number for each row?
UNIQUE
PRIMARY KEY
AUTO_INCREMENT
FOREIGN KEY

Correct!

Wrong!

6. Which SQL clause is used to group rows that have the same values in specified columns?
WHERE
GROUP BY
ORDER BY
SORT BY

Correct!

Wrong!

7. Which of the following is true about subqueries?
Subqueries can only return one value.
Subqueries cannot use the ORDER BY clause.
Subqueries are executed after the main query.
Subqueries can be used with the IN operator.

Correct!

Wrong!

8. Which clause is used to filter groups based on aggregate functions?
WHERE
GROUP BY
ORDER BY
HAVING

Correct!

Wrong!

9.Which clause is used to filter rows before grouping is applied?
WHERE
GROUP BY
AFTER
BEFORE

Correct!

Wrong!

10. Which operator checks for the existence of a value within a set?
BETWEEN
LIKE
IN
EXISTS

Correct!

Wrong!

11. Which type of JOIN returns all rows from the left table, and the matched rows from the right table?
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL OUTER JOIN

Correct!

Wrong!

12. The process of organizing data to reduce redundancy and improve data integrity is called:
Denormalization
Normalization
Optimization
Rationalization

Correct!

Wrong!

13. Which command is used to save changes in a transaction?
SAVE
COMMIT
END
FINISH

Correct!

Wrong!

14. To enforce a relationship between two tables, which constraint should you use?
PRIMARY KEY
FOREIGN KEY
UNIQUE
CHECK

Correct!

Wrong!

15. How can you find the number of employees in each department?
SELECT department_id, COUNT(employee_id) FROM employees GROUP BY department_id;
SELECT COUNT(employee_id), department_id FROM employees SORT BY department_id;
COUNT(employee_id) FROM employees ORDER BY department_id;
SELECT department_id FROM employees GROUP BY COUNT(employee_id);

Correct!

Wrong!

16. To sort employees first by department in ascending order and then by last name in descending order, the query is:
SELECT * FROM employees ORDER BY department_id ASC, last_name DESC;
SELECT * FROM employees ORDER BY department_id DESC, last_name ASC;
SELECT * FROM employees SORT BY department_id ASC, last_name DESC;
SELECT * FROM employees GROUP BY department_id ASC, last_name DESC;

Correct!

Wrong!

17. Which statement is true about using a subquery in the SELECT clause?
It can only return multiple values.
It's used to perform calculations that are used in the main SELECT statement.
It cannot be used in the SELECT clause.
It must always involve a JOIN.

Correct!

Wrong!

18. To filter groups by an aggregate function, such as having a total sales greater than $10,000, the clause used is:
WHERE total_sales > 10000
HAVING SUM(sales) > 10000
GROUP BY HAVING sales > 10000
ORDER BY sales > 10000

Correct!

Wrong!

19. To find employees whose names start with 'J', which operator is used?
IN
LIKE
BETWEEN
EQUALS

Correct!

Wrong!

20. The primary goal of the first normal form (1NF) in database normalization is to:
Remove all duplicate columns from the same table.
Separate different relations into different tables.
Ensure each table cell contains only single values.
Eliminate the need for foreign keys in database design.

Correct!

Wrong!

21. To revert changes made in the current transaction, which command would you use?
UNDO
ROLLBACK
RESET
CANCEL

Correct!

Wrong!

22. Which statement correctly adds a PRIMARY KEY constraint to an existing table named Employees?
ALTER TABLE Employees ADD CONSTRAINT PK_EmployeeID PRIMARY KEY (EmployeeID);
MODIFY TABLE Employees ADD CONSTRAINT PK_EmployeeID PRIMARY KEY (EmployeeID);
UPDATE TABLE Employees SET CONSTRAINT PK_EmployeeID PRIMARY KEY (EmployeeID);
CREATE TABLE Employees ADD CONSTRAINT PK_EmployeeID PRIMARY KEY (EmployeeID);

Correct!

Wrong!

23. Which statement uses a subquery to find employees who work in the same department as 'John Doe'?
SELECT * FROM Employees WHERE DepartmentID = (SELECT DepartmentID FROM Employees WHERE Name = 'John Doe');
SELECT * FROM Employees WHERE DepartmentID IN (SELECT DepartmentID FROM Employees WHERE Name = 'John Doe');
SELECT DepartmentID FROM Employees WHERE Name IN (SELECT DepartmentID FROM Employees WHERE Name = 'John Doe');
Both A and B are correct.

Correct!

Wrong!

24. To filter the result set to include only departments with a total salary expense greater than $1,000,000, which clause would you use?
WHERE SUM(Salary) > 1000000
HAVING SUM(Salary) > 1000000
WHERE COUNT(Salary) > 1000000
HAVING COUNT(Salary) > 1000000

Correct!

Wrong!

25. What does the CHECK constraint in SQL enforce when applied to a column in a table?
It ensures that the values in a column satisfy a specific condition set by the SQL expression in the constraint.
It checks for duplicate values in a column to ensure all entries are unique.
It automatically generates a numeric value for each row in a column.
It creates a link between two tables, enforcing referential integrity.

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Ignore & go to results

MYSQL – Quiz

You got %%score%% of %%total%% right

%%description%%

%%description%%

Loading...

Exit mobile version