Challenge - 5 Problems
Stored Procedure Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of a simple stored procedure call
Consider the following stored procedure in MySQL:
What will be the output when you execute
DELIMITER $$ CREATE PROCEDURE GetEmployeeCount() BEGIN SELECT COUNT(*) AS TotalEmployees FROM employees; END$$ DELIMITER ;
What will be the output when you execute
CALL GetEmployeeCount(); assuming the employees table has 50 rows?MySQL
CALL GetEmployeeCount();
Attempts:
2 left
💡 Hint
Stored procedures can return result sets using SELECT statements.
✗ Incorrect
The procedure runs a SELECT COUNT(*) query and returns the count as a result set. Since there are 50 rows, the output is one row with TotalEmployees = 50.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in stored procedure creation
Which option contains a syntax error when creating a stored procedure in MySQL?
MySQL
CREATE PROCEDURE SampleProc() BEGIN SELECT * FROM users; END;
Attempts:
2 left
💡 Hint
Check for missing semicolons inside the procedure body.
✗ Incorrect
Option A is missing a semicolon after the SELECT statement, causing a syntax error.
❓ optimization
advanced2:00remaining
Optimizing a stored procedure with parameters
You have a stored procedure that takes a department ID and returns employees in that department:
Which option improves this procedure to avoid confusion between parameter and column names?
CREATE PROCEDURE GetEmployeesByDept(IN dept_id INT) BEGIN SELECT * FROM employees WHERE department_id = dept_id; END;
Which option improves this procedure to avoid confusion between parameter and column names?
Attempts:
2 left
💡 Hint
Parameter names can conflict with column names; renaming helps clarity.
✗ Incorrect
Renaming the parameter to a unique name like IN_dept_id avoids ambiguity and ensures the correct value is used in the WHERE clause.
🔧 Debug
advanced2:00remaining
Debugging a stored procedure with variable assignment
What error will occur when running this stored procedure?
CREATE PROCEDURE CalcTotal() BEGIN DECLARE total INT; SET total = SELECT COUNT(*) FROM orders; SELECT total; END;
Attempts:
2 left
💡 Hint
Check the syntax for assigning query results to variables.
✗ Incorrect
You cannot assign a SELECT statement directly in SET. You must use SELECT ... INTO to assign query results to variables.
🧠 Conceptual
expert2:00remaining
Understanding transaction control in stored procedures
Which statement about transaction control inside MySQL stored procedures is correct?
Attempts:
2 left
💡 Hint
Think about how transactions work in MySQL and stored procedures.
✗ Incorrect
MySQL allows COMMIT and ROLLBACK inside stored procedures to manage transactions explicitly.