MySQL Database Quiz Questions

Course Name:MySQL
Chapter Name:Chapter 9 - Advanced Topics
Lesson Content Link:DB Function
Current Quiz Count:30
Progress
0%
Q1
True / False

MySQL, the NOW() function returns the current date and time.

Q2
True / False

The CONCAT() function in MySQL can be used to combine two or more strings into one string.

Q3
True / False

The COUNT() function in MySQL is used to calculate the total number of rows in a table.

Q4
True / False

The ROUND() function in MySQL can be used to round a number to a specified number of decimal places.

Q5
True / False

The SUBSTRING() function in MySQL extracts a specified number of characters from a string starting at a specified position.

Q6
True / False

The DATE_ADD() function in MySQL subtracts a time interval from a date.

Q7
True / False

The IFNULL() function in MySQL replaces NULL values with a specified replacement value.

Q8
True / False

The CAST() function in MySQL converts a value from one data type to another.

Q9
True / False

The GROUP_CONCAT() function in MySQL concatenates values from multiple rows into a single string.

Q10
True / False

MySQL, the DATE_FORMAT() function allows you to format a date value according to a specified format string.

Q11
Single Choice

What is the purpose of the NOW() function in MySQL?

Q12
Single Choice

Which function in MySQL is used to return the length of a string?

Q13
Single Choice

How do you convert a string to lowercase in MySQL?

Q14
Single Choice

Which function in MySQL can be used to extract a substring from a string?

Q15
Single Choice

What does the CONCAT() function do in MySQL?

Q16
Single Choice

How do you find the number of rows in a table using a function in MySQL?

Q17
Single Choice

Which MySQL function can be used to find the difference in days between two dates?

Q18
Single Choice

What does the COALESCE() function do in MySQL?

Q19
Single Choice

Which MySQL function is used to calculate the standard deviation of a set of values?

Q20
Single Choice

Which MySQL function can be used to perform a full-text search on a table?

Q21
Multiple Choice

Identify the correct SQL statement to create a user-defined function that returns the full name of a user.

SQL Code
CREATE FUNCTION get_full_name (first_name VARCHAR(100), last_name VARCHAR(100))
RETURNS VARCHAR(200)
BEGIN
RETURN CONCAT(first_name, ' ', last_name);
END;
Q22
Multiple Choice

Choose the correct SQL statement to create a function that calculates the square of a number.

SQL Code
CREATE FUNCTION calculate_square (number INT)
RETURNS INT
BEGIN
RETURN number * number;
END;
Q23
Multiple Choice

Determine the correct SQL statement to create a function that returns the average salary from the employees table.

SQL Code
CREATE FUNCTION get_average_salary ()
RETURNS DECIMAL(10,2)
BEGIN
DECLARE avg_salary DECIMAL(10,2);
SELECT AVG(salary) INTO avg_salary
FROM employees;
RETURN avg_salary;
END;
Q24
Multiple Choice

Which SQL statement correctly creates a function that checks if a user is active based on the last login date?

SQL Code
CREATE FUNCTION is_user_active (last_login DATE)
RETURNS BOOLEAN
BEGIN
RETURN last_login >= DATE_SUB(CURDATE(), INTERVAL 30 DAY);
END;
Q25
Multiple Choice

Select the correct SQL statement to create a function that returns the number of orders placed by a customer.

SQL Code
CREATE FUNCTION get_order_count (customer_id INT)
RETURNS INT
BEGIN
DECLARE order_count INT;
SELECT COUNT(*) INTO order_count
FROM orders
WHERE customer_id = customer_id;
RETURN order_count;
END;
Q26
Multiple Choice

Determine the correct SQL statement to create a function that calculates the discount for an order based on the order amount.

SQL Code
CREATE FUNCTION calculate_discount (order_amount DECIMAL(10,2))
RETURNS DECIMAL(10,2)
BEGIN
DECLARE discount DECIMAL(10,2);
IF order_amount > 100 THEN
SET discount = order_amount * 0.1;
ELSE
SET discount = 0;
END IF;
RETURN discount;
END;
Q27
Multiple Choice

Which SQL statement correctly creates a function that returns the number of days between two dates?

SQL Code
CREATE FUNCTION days_between (start_date DATE, end_date DATE)
RETURNS INT
BEGIN
RETURN DATEDIFF(end_date, start_date);
END;
Q28
Multiple Choice

Identify the correct SQL statement to create a function that returns the first day of the month for a given date.

SQL Code
CREATE FUNCTION first_day_of_month (input_date DATE)
RETURNS DATE
BEGIN
RETURN DATE_FORMAT(input_date, '%Y-%m-01');
END;
Q29
Multiple Choice

Select the correct SQL statement to create a function that checks if a string is a valid email format.

SQL Code
CREATE FUNCTION is_valid_email (email VARCHAR(255))
RETURNS BOOLEAN
BEGIN
RETURN email REGEXP '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}$';
END;
Q30
Multiple Choice

Determine the correct SQL statement to create a function that converts a string to title case (capitalizing the first letter of each word).

SQL Code
CREATE FUNCTION to_title_case (input_string VARCHAR(255))
RETURNS VARCHAR(255)
BEGIN
DECLARE result VARCHAR(255);
SET result = CONCAT(UCASE(LEFT(input_string, 1)), LCASE(SUBSTRING(input_string, 2)));
RETURN result;
END;