Stored Procedures in MySQL
Stored procedure is a segment of declarative SQL statements stored inside the MySQL Server. To define it other way, we can save (one or set) queries within stored procedure for future use. For example, we have a SELECT query that returns rows based on the condition SELECT * FROM customers WHERE city = ‘Bangalore’ ORDER BY firstName; The first time you invoke a stored procedure, MySQL looks up for the name in the database catalog, compiles the stored procedure’s code, place it in a memory area known as a cache, and execute the stored procedure. If you invoke the same stored procedure in the same session again, MySQL just executes the stored procedure from the cache without having to recompile it. A stored procedure can have parameters so you can pass values to it and get the result back. Advantages Reduce network traffic Centralize business logic More secure Disadvantages Resource Usages Troubleshooting Maintenance Creating Stored Procedures If we ...