CREATION OF STORED PROCEDURES IN MySQL 1. AIM To study and implement Stored Procedures in MySQL. 2. THEORY ✔ What is a Stored Procedure? A Stored Procedure is a precompiled block of SQL statements stored in the database and executed on demand. ✔ Advantages of Stored Procedures Improves performance (precompiled) Ensures reusability of code Helps maintain data integrity Reduces network traffic Provides security by restricting direct table access 3. GENERAL SYNTAX (MySQL) MySQL requires the DELIMITER command when creating procedures to avoid conflict with semicolons. DELIMITER $$ CREATE PROCEDURE procedure_name (parameter_list) BEGIN SQL statements; END $$ DELIMITER ; ✔ Calling a Procedure CALL procedure_name(arguments); 4. EXAMPLES ⭐ Example 1: Procedure Without Parameters ▶ Create a table for demonstration CREATE TABLE employees ( id INT PRIMARY KEY, name VARCHAR ( 100 ), salary DECIMAL ( 10 , 2 ) ); ▶ Inse...
Comments
Post a Comment