4. SQL Exercise - Stored Procedure
4. SQL Exercise - Stored Procedure
Database Schema
The following schema defines the structure for an Employee Management System:
Departments Table
Employees Table
Sample Data
The following sample data can be used for testing:
Exercises
Steps:
2. Write the SQL query to select employee details based on the DepartmentID.
Steps:
Steps:
Steps:
1. Write the SQL command to execute the stored procedure with a DepartmentID
parameter.
Steps:
2. Write the SQL query to count the number of employees in the specified department.
Steps:
1. Define the stored procedure with a parameter for DepartmentID and an output
parameter for total salary.
2. Write the SQL query to calculate the total salary of employees in the specified
department.
Steps:
1. Open SQL Server Management Studio (SSMS).
2. Connect to your database.
3. Create a stored procedure named `sp_UpdateEmployeeSalary` to update employee salary
4. Execute the stored procedure with the following code:
EXEC sp_UpdateEmployeeSalary 1, 5500.00;
Goal: Create a stored procedure to give a bonus to employees based on their department.
Steps:
1. Open SQL Server Management Studio (SSMS).
2. Connect to your database.
3. Create a stored procedure named `sp_GiveBonus` to give a bonus to employees based on
their department.
4. Execute the stored procedure with the following code:
Steps:
1. Define the stored procedure with parameters for EmployeeID and new Salary.
Steps:
1. Define the stored procedure with parameters for filter column and filter value.
2. Write the dynamic SQL query to retrieve employee details based on the filter.
Steps:
1. Define the stored procedure with parameters for EmployeeID and new Salary.