MySQL + SQL · Lesson 95

Stored Procedures in MySQL

What is a Stored Procedure?

A stored procedure is a saved block of SQL you can run by name, with parameters. It saves repeating the same logic.

Create and Call

DELIMITER //
CREATE PROCEDURE add_student(IN p_name VARCHAR(50), IN p_marks INT)
BEGIN
    INSERT INTO students(name, marks) VALUES(p_name, p_marks);
END //
DELIMITER ;

CALL add_student('Aman', 88);
CALL runs the saved procedure with the given values.

Why Use Them?

  • Reuse complex logic by name.
  • Reduce network traffic (one CALL vs many queries).
  • Centralise business rules in the database.

Summary

  • A stored procedure is saved SQL run with CALL.
  • Use IN parameters to pass values; great for reusable logic.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n

💻 Live Code Editor

Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.
Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.

💻 Live Code Editor

Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें. Agar load na ho to naye tab mein kholें.