TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst ยท 76.7K subscribers
Post #2436 3.03K
โœ… Stored Procedures ๐Ÿ’ฏ

๐Ÿง  1. What is a Stored Procedure?
A Stored Procedure is a saved SQL program
โ€ข Stored inside the database
โ€ข Can be executed anytime

Think like this ๐Ÿ‘‡
โ€œReusable SQL code blockโ€

โšก 2. Why Use Stored Procedures?
โ€ข Reuse SQL logic
โ€ข Reduce repeated code
โ€ข Better security
โ€ข Faster execution for repeated tasks

โšก 3. Basic Syntax

๐Ÿ‘‰ MySQL Example:
DELIMITER //

CREATE PROCEDURE GetEmployees()
BEGIN
SELECT * FROM employees;
END //

DELIMITER ;

โ–ถ๏ธ 4. Execute Stored Procedure
CALL GetEmployees();

๐Ÿ”ฅ 5. Procedure with Parameter
DELIMITER //

CREATE PROCEDURE GetDeptEmployees(IN dept_name VARCHAR(50))
BEGIN
SELECT * FROM employees
WHERE department = dept_name;
END //

DELIMITER ;

โ–ถ๏ธ 6. Execute Parameterized Procedure
CALL GetDeptEmployees('IT');

โŒ 7. Drop Stored Procedure
DROP PROCEDURE GetEmployees;

๐ŸŽฏ 8. Real Example
Increase salary for all IT employees:

DELIMITER //

CREATE PROCEDURE IncreaseSalary()
BEGIN
UPDATE employees
SET salary = salary + 5000
WHERE department = 'IT';
END //

DELIMITER ;

๐ŸŽฏ 9. Practice Tasks
1. Create procedure to show all employees
2. Create procedure for HR employees
3. Create procedure with salary parameter
4. Execute stored procedure
5. Drop procedure

โšก Mini Challenge ๐Ÿ”ฅ

Create procedure to return employees with salary > given value

โœ… Solution

DELIMITER //

CREATE PROCEDURE GetHighSalaryEmployees(IN min_salary INT)
BEGIN
SELECT *
FROM employees
WHERE salary > min_salary;
END //

DELIMITER ;

โ–ถ๏ธ Execute Procedure

CALL GetHighSalaryEmployees(50000);

โœ” Returns employees earning more than 50k

Key Difference:
โ€ข Function โ†’ returns value
โ€ข Procedure โ†’ performs action / multiple operations

Double Tap โค๏ธ For More
  • โค 7
More from @sqlanalyst
  1. Oct 9, 2026SQL Interview Series โ€” Part 5 ๐Ÿ“Œ Question 5: Find Employees Who Earn More Than Their Managโ€ฆ
  2. Oct 9, 2026๐Ÿ‡ฎ๐Ÿ‡ณ ๐—š๐—ข๐—ฉ๐—˜๐—ฅ๐—ก๐— ๐—˜๐—ก๐—ง ๐—ข๐—™ ๐—œ๐—ก๐——๐—œ๐—” โ€” ๐—”๐—œ๐—–๐—ง๐—˜ ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ ๐Ÿš€โ€ฆ
  3. Oct 8, 2026๐ŸŽ“ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐˜€! ๐Ÿš€๐Ÿ”ฅ Upgrโ€ฆ
  4. Oct 7, 2026๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐโ€ฆ
  5. Oct 7, 2026SQL Interview Series โ€” Part 4 ๐Ÿ“Œ Question 4: Find the Highest Salary in Each Department Suโ€ฆ
  6. Oct 7, 2026๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ”ฅ Learn Power BI through these FREE learninโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’