Function vs Procedure Decision in SQL
📖 Scenario: You work at a small company that manages employee data. You need to create reusable database code to calculate employee bonuses and to update employee records.
🎯 Goal: Build a simple SQL function to calculate a bonus based on salary and a procedure to update an employee's department.
📋 What You'll Learn
Create a function named
calculate_bonus that takes salary as input and returns 10% of it.Create a procedure named
update_department that takes employee_id and new_department as inputs and updates the employee's department.Use the function inside the procedure to calculate the bonus for the employee.
Ensure the function returns a value and the procedure performs an update without returning a value.
💡 Why This Matters
🌍 Real World
Companies often use functions to calculate values like bonuses or taxes and procedures to update employee records or perform complex operations.
💼 Career
Understanding when to use functions versus procedures is important for database developers and administrators to write efficient and maintainable SQL code.
Progress0 / 4 steps