Here, we pass a parameter of 1 which is the ID for Apple. Here's the syntax for creating a stored procedure: Stored procedures are created using the CREATE PROCEDURE statement. Therefore, you could call the stored procedure, each time with a different fruit ID and it would return a value that shows you how much of that fruit is in stock. The stored procedure could then take that parameter and use it to check the inventory for that particular fruit. The stored procedure will then execute, using your parameters in any way that the code specifies.įor example, you could write a stored procedure that accepts a FruitId parameter. When you call it, you also provide any parameters that it might require. Then once it has been created, you can run it (or more precisely, you "call" it). How Do Stored Procedures Work?įirst of all, you create the stored procedure. A stored procedure can accept parameters, and you can set variables, write IF statements, etc within a stored procedure. A stored procedure can contain business logic, which is one of the key aspects that distinguishes stored procedures from views. Stored procedures are a powerful part of MySQL (and other database management systems, such as SQL Server) and they allow you to do more than views do.Ī stored procedure is a collection of SQL statements that are stored in the database. MySQL provides us with the ability to create stored procedures.
0 Comments
Leave a Reply. |