A stored procedure is a named block of SQL, and sometimes procedural code, stored inside the database server and executed by calling its name with parameters.
Why it matters
Procedures keep logic next to the data, which cuts network round trips and lets you grant access to an operation without granting access to the underlying tables. They can also centralize rules shared by several applications. Teams that use them heavily often treat the procedure code like any other source file and deploy it through migrations. The downsides are harder version control, testing, and portability, since the syntax differs between database systems.
Example
-- MySQL style
CREATE PROCEDURE add_credit(IN uid BIGINT, IN amt DECIMAL(10,2))
BEGIN
UPDATE wallets SET balance = balance + amt WHERE user_id = uid;
END;
CALL add_credit(42, 50.00);
Common mistakes
- Hiding large amounts of business logic in procedures that are not kept in source control.
- Building procedure bodies from concatenated strings, which brings back injection risk.
- Assuming procedures are always faster. Gains come mostly from fewer round trips.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.