A stored procedure is a named, precompiled block of SQL logic saved in the database that can be executed repeatedly by applications passing in parameters. It centralizes reusable logic on the database side instead of duplicating that logic across application code.
An e-commerce application frequently needs to apply a discount to an order total; rather than repeating that calculation in every service that processes orders, it defines an ApplyDiscount procedure once and calls it with the order amount and discount rate.
DELIMITER //
CREATE PROCEDURE ApplyDiscount(
IN orderAmount DECIMAL(10, 2),
IN discountRate DECIMAL(5, 2)
)
BEGIN
DECLARE finalAmount DECIMAL(10, 2);
SET finalAmount = orderAmount - (orderAmount * discountRate / 100);
SELECT finalAmount AS Final_Amount;
END //
DELIMITER ;
CALL ApplyDiscount(1000.00, 10.00);A concise interview answer is
A stored procedure is precompiled SQL logic saved in the database that I can call repeatedly with parameters, using CREATE PROCEDURE and then CALL. I'd use one to centralize logic like applying a discount to an order total, so every caller gets consistent behavior and I'm not duplicating the calculation across the application.
Last updated: 11 November 2026
Previous question: What is a trigger, and how do you create one in MySQL?
Next question: What is a cursor, and how do you use one in MySQL?