
Characters:
- Chef Siva – A master chef in a busy restaurant.
- Waiter Ravi – Takes customer orders.
- Kitchen – Like a database.
- Recipe Book – Like stored procedures.
The Story:
Every day, customers come to Chef Siva’s restaurant and order different dishes. Waiter Ravi runs to the kitchen and gives Chef Siva the order:
“One Masala Dosa, please!”
Now, imagine if every time someone ordered Masala Dosa, Chef Siva had to remember all the steps:
- Take batter from fridge
- Heat the pan
- Pour batter
- Cook one side
- Add filling
- Fold and serve
Doing this manually every time is tiring.
So one day, Chef Siva writes down all the steps in a recipe book and tells Ravi:
“From now on, whenever someone orders Masala Dosa, just say ‘Run Recipe for Masala Dosa’ and I’ll follow the steps.”
This recipe becomes a stored procedure.
What is a Procedure (in database terms)?
A procedure is a saved set of SQL commands (like a recipe) that you can run again and again by calling its name.
Example:
CREATE PROCEDURE GetCustomerOrders
@CustomerID INT
AS
BEGIN
SELECT * FROM Orders WHERE CustomerID = @CustomerID;
END;
Now, instead of writing the query each time, you just run:
EXEC GetCustomerOrders 123;
Why Do We Need Procedures?
- Reusability: Write once, use many times.
- Simplicity: Others can use it without knowing SQL details.
- Security: You can give users access to procedures, not direct tables.
- Maintenance: If logic changes, update the procedure, not every report/app.
Final Scene
:
Chef Siva becomes famous – orders are served fast, Ravi doesn’t get tired explaining steps, and the kitchen is peaceful.
“That’s the power of a procedure – one smart recipe can serve hundreds without chaos!”
Leave a Reply