MySQL Database Quiz Questions

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

A MySQL stored procedure can be used to encapsulate SQL statements for reuse.

Q2
True / False

In MySQL, a stored procedure cannot accept input parameters.

Q3
True / False

MySQL stored procedures are only available in the Enterprise edition of MySQL.

Q4
True / False

A MySQL stored procedure can return multiple result sets.

Q5
True / False

MySQL, you can use the DELIMITER keyword to change the delimiter while defining a stored

Q6
True / False

MySQL stored procedures cannot include transaction control statements like COMMIT and ROLLBACK.

Q7
True / False

MySQL stored procedures support error handling using the DECLARE ... HANDLER statement

Q8
True / False

In MySQL, you cannot call a stored procedure from within another stored procedure.

Q9
True / False

MySQL stored procedures can be used to implement complex business logic that cannot be achieved with simple SQL queries.

Q10
True / False

MySQL, the INVOKER security context is the default for stored procedures unless otherwise specified.

Q11
Single Choice

What is a stored procedure in MySQL?

Q12
Single Choice

How do you create a stored procedure in MySQL?

Q13
Single Choice

Which command is used to execute a stored procedure in MySQL?

Q14
Single Choice

How do you define an input parameter in a MySQL stored procedure?

Q15
Single Choice

How can you handle errors in a MySQL stored procedure?

Q16
Single Choice

Which keyword is used to define a variable inside a MySQL stored procedure?

Q17
Single Choice

How do you return multiple result sets from a MySQL stored procedure?

Q18
Single Choice

How do you create a stored procedure with optional parameters in MySQL?

Q19
Single Choice

Which command is used to delete a stored procedure in MySQL?

Q20
Single Choice

Which privilege is required to create a stored procedure in MySQL?

Q21
Multiple Choice

Identify the correct SQL statement to create a stored procedure that inserts a new record into a table.

SQL Code
CREATE PROCEDURE insert_employee (IN emp_name VARCHAR(100), IN emp_salary DECIMAL(10,2))
BEGIN
INSERT INTO employees (name, salary)
VALUES (emp_name, emp_salary);
END;
Q22
Multiple Choice

Choose the correct SQL statement to create a stored procedure that updates an employee's salary based on their ID.

SQL Code
CREATE PROCEDURE update_salary (IN emp_id INT, IN new_salary DECIMAL(10,2))
BEGIN
UPDATE employees
SET salary = new_salary
WHERE id = emp_id;
END;
Q23
Multiple Choice

Determine the correct SQL statement to create a stored procedure that deletes an employee record based on their ID.

SQL Code
CREATE PROCEDURE delete_employee (IN emp_id INT)
BEGIN
DELETE FROM employees
WHERE id = emp_id;
END;
Q24
Multiple Choice

Which SQL statement correctly creates a stored procedure that retrieves an employee's details based on their ID?

SQL Code
CREATE PROCEDURE get_employee_details (IN emp_id INT)
BEGIN
SELECT * FROM employees
WHERE id = emp_id;
END;
Q25
Multiple Choice

Select the correct SQL statement to create a stored procedure that counts the number of employees in a department.

SQL Code
CREATE PROCEDURE count_employees_in_department (IN dept_id INT)
BEGIN
SELECT COUNT(*) FROM employees
WHERE department_id = dept_id;
END;
Q26
Multiple Choice

Determine the correct SQL statement to create a stored procedure that calculates the total sales for a given month.

SQL Code
CREATE PROCEDURE calculate_total_sales (IN sale_month DATE)
BEGIN
DECLARE total_sales DECIMAL(10,2);
SELECT SUM(amount) INTO total_sales
FROM sales
WHERE MONTH(sale_date) = MONTH(sale_month);
RETURN total_sales;
END;
Q27
Multiple Choice

Which SQL statement correctly creates a stored procedure that logs changes made to employee salaries?

SQL Code
CREATE PROCEDURE log_salary_changes (IN emp_id INT, IN old_salary DECIMAL(10,2), IN new_salary DECIMAL(10,2))
BEGIN
INSERT INTO salary_log (employee_id, old_salary, new_salary, change_date)
VALUES (emp_id, old_salary, new_salary, NOW());
END;
Q28
Multiple Choice

Identify the correct SQL statement to create a stored procedure that checks for duplicate entries before inserting a new record.

SQL Code
CREATE PROCEDURE insert_unique_employee (IN emp_name VARCHAR(100), IN emp_salary DECIMAL(10,2))
BEGIN
IF NOT EXISTS (SELECT 1 FROM employees WHERE name = emp_name) THEN
INSERT INTO employees (name, salary)
VALUES (emp_name, emp_salary);
END IF;
END;
Q29
Multiple Choice

Select the correct SQL statement to create a stored procedure that processes a batch of records in a loop.

SQL Code
CREATE PROCEDURE process_records ()
BEGIN
DECLARE finished INT DEFAULT 0;
DECLARE record_id INT;
DECLARE cur CURSOR FOR SELECT id FROM records WHERE processed = 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;
OPEN cur;
record_loop: LOOP
FETCH cur INTO record_id;
IF finished THEN
LEAVE record_loop;
END IF;
-- Processing logic here
END LOOP;
CLOSE cur;
END;
Q30
Multiple Choice

Determine the correct SQL statement to create a stored procedure that rolls back a transaction if an error occurs.

SQL Code
CREATE PROCEDURE safe_transaction ()
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
END;
START TRANSACTION;
-- Transaction logic here
COMMIT;
END;