Complete the code to start creating a stored procedure named 'GetAllUsers'.
CREATE [1] PROCEDURE GetAllUsers() BEGIN SELECT * FROM users; END;The keyword PROCEDURE is used to create a stored procedure in MySQL.
Complete the code to declare an input parameter named 'userId' of type INT in the stored procedure.
CREATE PROCEDURE GetUserById([1] userId INT) BEGIN SELECT * FROM users WHERE id = userId; END;The IN keyword declares an input parameter for a stored procedure.
Fix the error in the stored procedure declaration by completing the missing delimiter statement.
DELIMITER [1] CREATE PROCEDURE CountUsers() BEGIN SELECT COUNT(*) FROM users; END[1] DELIMITER ;
Changing the delimiter to $$ allows the procedure body to contain semicolons without ending the statement early.
Fill both blanks to create a procedure that updates a user's email by id.
CREATE PROCEDURE UpdateUserEmail(IN userId INT, IN newEmail VARCHAR(255)) BEGIN UPDATE users SET email = [1] WHERE id = [2]; END;
The procedure sets the email column to the input parameter newEmail where the id matches the input parameter userId.
Fill all three blanks to create a procedure that inserts a new user with name and age, then returns the new user's id.
CREATE PROCEDURE AddUser(IN userName VARCHAR(100), IN userAge INT, OUT newId INT) BEGIN INSERT INTO users (name, age) VALUES ([1], [2]); SET [3] = LAST_INSERT_ID(); END;
The procedure inserts the input parameters userName and userAge into the users table, then sets the output parameter newId to the last inserted id.