Q1
True / FalseA MySQL stored procedure can be used to encapsulate SQL statements for reuse.
Stored procedures allow you to save a series of SQL statements and reuse them, which can simplify complex operations and improve code maintainability.
Q2
True / FalseIn MySQL, a stored procedure cannot accept input parameters.
MySQL stored procedures can accept input parameters, which allows for dynamic execution based on the provided inputs.
Q3
True / FalseMySQL stored procedures are only available in the Enterprise edition of MySQL.
MySQL stored procedures are available in both the Community and Enterprise editions of MySQL.
Q4
True / FalseA MySQL stored procedure can return multiple result sets.
MySQL stored procedures can return multiple result sets by executing multiple SELECT statements within the procedure.
Q5
True / FalseMySQL, you can use the DELIMITER keyword to change the delimiter while defining a stored
The DELIMITER keyword is used in MySQL to change the statement delimiter temporarily, allowing the procedure to be defined without interference from the default delimiter ;.
Q6
True / FalseMySQL stored procedures cannot include transaction control statements like COMMIT and ROLLBACK.
MySQL stored procedures can include transaction control statements such as COMMIT and ROLLBACK, allowing for better control over transaction management within the procedure.
Q7
True / FalseMySQL stored procedures support error handling using the DECLARE ... HANDLER statement
MySQL allows for error handling in stored procedures using the DECLARE ... HANDLER statement to define actions for specific error conditions.
Q8
True / FalseIn MySQL, you cannot call a stored procedure from within another stored procedure.
MySQL supports nested stored procedure calls, meaning you can call a stored procedure from within another stored procedure.
Q9
True / FalseMySQL stored procedures can be used to implement complex business logic that cannot be achieved with simple SQL queries.
Stored procedures can include complex control flow logic, loops, conditionals, and other programming constructs that enable the implementation of sophisticated business logic.
Q10
True / FalseMySQL, the INVOKER security context is the default for stored procedures unless otherwise specified.
The default security context for MySQL stored procedures is DEFINER, not INVOKER. This means the stored procedure executes with the privileges of the user who defined it, unless explicitly set to INVOKER.
Q21
Multiple ChoiceIdentify 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;
This stored procedure takes two input parameters and inserts them into the employees table.
Q22
Multiple ChoiceChoose 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;
This stored procedure takes an employee ID and a new salary as input and updates the corresponding record in the employees table.
Q27
Multiple ChoiceWhich 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;
This stored procedure logs the changes made to an employee's salary in the salary_log table, recording the old and new salaries along with the change date.
Q28
Multiple ChoiceIdentify 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;
This stored procedure checks if an employee with the same name already exists in the employees table before inserting a new record.