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 that returns the total count of employees in a company.
What will be the output of calling
What will be the output of calling
EXEC GetEmployeeCount; if the Employees table has 150 rows?Testing Fundamentals
CREATE PROCEDURE GetEmployeeCount AS BEGIN SELECT COUNT(*) AS TotalEmployees FROM Employees; END;
Attempts:
2 left
💡 Hint
The procedure counts all rows in the Employees table.
✗ Incorrect
The procedure runs a SELECT COUNT(*) query on the Employees table, which has 150 rows, so it returns 150 as TotalEmployees.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in stored procedure
Which option contains a syntax error when creating a stored procedure that inserts a new employee?
Testing Fundamentals
CREATE PROCEDURE AddEmployee @Name VARCHAR(50), @Age INT AS BEGIN INSERT INTO Employees (Name, Age) VALUES (@Name, @Age); END;Attempts:
2 left
💡 Hint
Check for missing keywords or misplaced syntax in procedure declaration.
✗ Incorrect
Option B is missing the AS keyword before BEGIN, which is required in stored procedure syntax.
❓ optimization
advanced2:00remaining
Optimizing a stored procedure for performance
A stored procedure retrieves all orders for a customer by joining Orders and Customers tables. Which option improves performance by reducing unnecessary data retrieval?
Testing Fundamentals
CREATE PROCEDURE GetCustomerOrders @CustomerID INT AS BEGIN SELECT * FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.ID WHERE Customers.ID = @CustomerID; END;
Attempts:
2 left
💡 Hint
Avoid joining tables if not needed and select only required columns.
✗ Incorrect
Option A selects only Orders columns and filters by CustomerID without joining Customers table, reducing data processed and improving performance.
🔧 Debug
advanced2:00remaining
Debugging a stored procedure with parameter issues
A stored procedure is supposed to update an employee's salary but does not change any data when called. Which option explains the likely cause?
Testing Fundamentals
CREATE PROCEDURE UpdateSalary @EmpID INT, @NewSalary DECIMAL(10,2) AS BEGIN UPDATE Employees SET Salary = @NewSalary WHERE EmployeeID = @EmpID; END;
Attempts:
2 left
💡 Hint
Check if the parameters passed when calling the procedure match the defined names.
✗ Incorrect
If the procedure is called with incorrect parameter names or order, the UPDATE may not affect any rows because the filter condition fails.
🧠 Conceptual
expert3:00remaining
Understanding transaction handling in stored procedures
Which option best describes what happens if a stored procedure contains multiple UPDATE statements inside a transaction and one UPDATE fails?
Attempts:
2 left
💡 Hint
Think about atomicity in transactions.
✗ Incorrect
Transactions ensure all-or-nothing behavior; if one UPDATE fails, the entire transaction rolls back to maintain data integrity.