src/data/question-groups/sql/content/stored-procedures.md
Stored procedures are like saved functions in your SQL code that you write once and can run repeatedly. They're stored directly in the database, which gives them a few benefits:
For example, if you have an application that constantly pulls employee data, you can create a stored procedure for it to optimize the process.
-- Create a stored procedure to get employees by department
CREATE PROCEDURE GetEmployeesByDepartment
@DepartmentID INT
AS
BEGIN
SELECT name, hire_date, salary
FROM employees
WHERE department_id = @DepartmentID
ORDER BY hire_date DESC;
END;
-- Call the procedure
EXEC GetEmployeesByDepartment @DepartmentID = 3;
Stored procedures are especially useful in enterprise systems where performance, security, and consistent logic are important.