MySQL Online Test - MCQ Questions

Welcome to the MySQL Online Test! We will present 25 MCQs (Multiple-Choice Questions) to test your knowledge of the the MySQL database.

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 is the result of the following MySQL query?

SELECT CONCAT(FirstName, ' ', LastName) AS FullName FROM Users;
a) Splits the FullName into FirstName and LastName
b) Merges FirstName and LastName into FullName
c) Counts the number of users
d) Deletes the FirstName and LastName fields

2. What will the following MySQL query return?

SELECT * FROM Products WHERE Quantity <= 10 ORDER BY Quantity DESC LIMIT 3;
a) The three highest quantities greater than 10
b) The three lowest quantities
c) The three highest quantities less than or equal to 10
d) All quantities less than or equal to 10

3. How do you select the current date and time in MySQL?

a) SELECT CURRENT_TIMESTAMP;
b) SELECT NOW();
c) SELECT GETDATE();
d) SELECT TIMESTAMP();

4. What does the following query do in MySQL?

UPDATE Employees SET Age = Age + 1 WHERE Birthday = CURDATE();
a) Decreases the age of all employees by one year
b) Increases the age of all employees by one year
c) Increases the age of employees whose birthday is today
d) Decreases the age of employees whose birthday is today

5. Which SQL statement is used to remove duplicates from a result set in MySQL?

a) SELECT UNIQUE
b) SELECT DISTINCT
c) SELECT DIFFERENT
d) SELECT ALONE

6. What is the purpose of the GROUP BY statement in MySQL?

a) To aggregate data across multiple records
b) To sort the result set in ascending order
c) To include condition-based selection in the query
d) To limit the number of records in the result set

7. How would you write a query to list all databases in your MySQL server?

SHOW DATABASES;
a) The given query
b) LIST ALL DATABASES;
c) SELECT DATABASES();
d) GET DATABASES;

8. What is the result of this MySQL query?

SELECT DATE_ADD('2023-01-01', INTERVAL 1 MONTH);
a) Returns the date one month after January 1, 2023
b) Returns the date one month before January 1, 2023
c) Adds one month to all dates in the database
d) Subtracts one month from January 1, 2023

9. How do you rename a table in MySQL?

RENAME TABLE old_table TO new_table;
a) The given query
b) CHANGE TABLE old_table TO new_table;
c) UPDATE TABLE old_table TO new_table;
d) ALTER TABLE old_table RENAME TO new_table;

10. What does the AUTO_INCREMENT attribute do in MySQL?

a) Automatically decreases the value of the column by 1 each time a new record is added
b) Automatically increases the value of the column by 1 each time a new record is added
c) Automatically deletes the value in the column when a new record is inserted
d) Automatically updates the value in the column when a new record is modified

11. Which command is used to delete an existing database in MySQL?

a) DROP DATABASE databasename;
b) REMOVE DATABASE databasename;
c) DELETE DATABASE databasename;
d) ERASE DATABASE databasename;

12. How do you view all the columns and their properties in a table in MySQL?

SHOW COLUMNS FROM tablename;
a) The given query
b) DESCRIBE tablename;
c) DISPLAY COLUMNS FROM tablename;
d) Both a) and b) are correct

13. What does the LIKE clause do in a MySQL query?

a) Finds rows matching a specified pattern
b) Limits the result set to likes only
c) Sorts results in alphabetical order
d) Connects to the database

14. What is the effect of the INNER JOIN keyword in MySQL?

a) Returns rows when there is at least one match in both tables
b) Returns all rows from both tables, with the matching rows from one of the tables
c) Returns rows from the first table and the matched rows from the second table
d) Returns only the rows from both tables that are different

15. What is the use of the HAVING clause in MySQL?

a) To specify filtering conditions for groups created by GROUP BY
b) To specify filtering conditions before data is grouped
c) To filter records after they have been ordered
d) To check for conditions on the SELECT clause

16. What does the MySQL function ROUND(number, decimals) do?

a) Rounds a number to the nearest integer
b) Rounds a number to a specified number of decimal places
c) Converts a number to a rounded integer string
d) Returns the integer part of a number

17. How do you add a primary key to an existing MySQL table?

ALTER TABLE tablename ADD PRIMARY KEY (columnname);
a) The given query
b) UPDATE TABLE tablename SET PRIMARY KEY (columnname);
c) INSERT PRIMARY KEY ON tablename (columnname);
d) None of the above

18. Which MySQL clause is used to limit the number of rows returned in a query result?

a) LIMIT
b) RESTRICT
c) CONSTRAINT
d) BOUND

19. What is a stored procedure in MySQL?

a) A set of SQL commands saved as a file in the database
b) A method to update the table structure
c) A prepared SQL code that you can save and reuse
d) An API provided by MySQL to connect to other databases

20. What is the purpose of the FOREIGN KEY constraint in MySQL?

a) To prevent invalid data entry into a column
b) To link two tables together
c) To uniquely identify each row in a database table
d) To speed up data retrieval

21. How do you create a view in MySQL?

CREATE VIEW view_name AS
SELECT column1, column2
FROM table_name
WHERE condition;
a) The given query
b) CREATE VIEW AS SELECT FROM table_name;
c) DEFINE VIEW view_name AS SELECT FROM table_name;
d) None of the above

22. How can you ensure that a field in a table only accepts values that are not NULL?

a) Use the NOT NULL constraint
b) Use the UNIQUE constraint
c) Use the CHECK constraint
d) Use the EXCLUDE constraint

23. What is an alias in MySQL?

a) A temporary name assigned to a table or column
b) A permanent name used to replace the original name of the column
c) A name given to a database
d) A name given to a user-defined function

24. What happens when you execute the following SQL statement in MySQL?

DROP TABLE IF EXISTS Employees;
a) It creates a new table called Employees if it doesn't exist
b) It deletes the Employees table only if it exists
c) It renames the Employees table if it exists
d) It updates the Employees table if it exists

25. What is the purpose of the AS keyword in SQL?

a) To rename a column or table using an alias
b) To specify the datatype of a column
c) To hide the original names of columns from users
d) To define a condition in a query

Comments