Site icon TestingDocs.com

MySQL Stored Procedures

MySQL Stored Procedures

A stored procedure is a set of SQL statements that can be executed on the database server. These procedures are stored in the database and can be invoked by applications or users. Stored procedures provide advantages such as improving performance, reusability, and security by encapsulating logic on the server side.

Key Benefits of Using Stored Procedures:

Example of a MySQL Stored Procedure


CREATE PROCEDURE AddEmployee(
    IN emp_name VARCHAR(100),
    IN emp_position VARCHAR(50),
    IN emp_salary DECIMAL(10, 2)
)
BEGIN
    INSERT INTO employees (name, position, salary)
    VALUES (emp_name, emp_position, emp_salary);
END //


Calling the Stored Procedure


CALL AddEmployee('John Doe', 'Manager', 60000.00);
  

This will insert a new employee named “John Doe” with the position of “Manager” and a salary of 60000 into the employees table.

Exit mobile version