How to do it...

For example, you want to add a new employee. You should update three tables, namely employees, salaries, and titles. Instead of executing three statements, you can develop a stored procedure and call it to create a new employee.

You have to pass the employee's first_name, last_name, gender, and birth_date, as well as the department the employee joins. You can pass those using input variables and you should get the employee number as output. The stored procedure does not return a value, but it can update a variable and you can use it.

Here is a simple example of a stored procedure to create a new employee and update the salary and department tables:

/* DROP the existing procedure if any with the same name before creating */ ...

Get MySQL 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.