O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 */ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required