← Back to MySQL Course | Chapter 15: Stored Procedures & Functions | Lesson 1 of 5

Stored Procedures

एक stored procedure database के अंदर रखे एक recipe card जैसा है। आप इसे नाम से call करते हैं और इसके सारे steps एक साथ चलते हैं।
Syntax
sql
DELIMITER //
CREATE PROCEDURE procedure_name()
BEGIN
  -- SQL statements
END //
DELIMITER ;

CALL procedure_name();

Stored Procedures का Introduction

एक stored procedure SQL statements के एक group को साथ bundle करता है और उन्हें database के अंदर एक नाम के तहत save करता है, ताकि उस पूरी sequence को हर बार application से दोबारा type या resend किए बिना demand पर फिर से चलाया जा सके।

उदाहरण: Introduction to Stored Procedures

sql
DELIMITER //
CREATE PROCEDURE GetAllUsers()
BEGIN
  SELECT * FROM users;
END //
DELIMITER ;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

एक Stored Procedure Call करना

एक बार defined होने पर, एक stored procedure को CALL statement से execute किया जाता है, जो इसके अंदर saved हर query को work की एक single unit की तरह order में चलाने के लिए trigger करता है।

उदाहरण: Calling a Stored Procedure

sql
CALL GetAllUsers();

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

एक Stored Procedure Drop करना

DROP PROCEDURE permanently एक saved procedure हटाता है। statement में IF EXISTS add करना एक error रोकता है अगर procedure पहले से delete हो चुका था या पहली जगह कभी exist ही नहीं करता था।

उदाहरण: Dropping a Stored Procedure

sql
DROP PROCEDURE IF EXISTS GetAllUsers;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Stored Procedures List करना

आप किसी database में currently defined हर stored procedure list कर सकते हैं, जो नई, शायद duplicate, procedures लिखने से पहले यह फिर से discover करने का एक उपयोगी तरीका है कि कौन सा reusable logic पहले से available है।

उदाहरण: Listing Stored Procedures

sql
SHOW PROCEDURE STATUS WHERE Db = DATABASE();

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Stored Procedures के Benefits

Stored procedures network पर आगे-पीछे भेजे गए data की मात्रा कम करते हैं क्योंकि सिर्फ CALL और इसके arguments travel करते हैं, और वे table structure details को एक fixed interface के पीछे छुपाकर एक security layer add करते हैं।

उदाहरण: Benefits of Stored Procedures

sql
-- One CALL travels over the network instead of several separate queries,
-- and the caller never needs to know the underlying table structure.
CALL GetAllUsers();

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. DELIMITER // भूल जाना, ताकि MySQL body के अंदर पहले ; पर statement खत्म कर दे और एक syntax error दे।
  2. बाद में DELIMITER ; से वापस switch करना भूल जाना, ताकि normal statements न चलें।
  3. CALL GetAllUsers() के बजाय SELECT GetAllUsers() से एक procedure call करना।
🔒

Chapter Quiz — Complete all 5 topics to unlock

0/5 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.