Question-1
You have been assigned to create a database procedure that calculates the average salary of
employees in a specific department. Write a stored procedure in SQL that takes the department ID as
input and returns the average salary of employees in that department. Assume you have the
following tables:
Table: Employees
1D Name Salary Department
a John 50000 HR
2 Mary 60000 Finance
3 David 55000 HR
4 Linda 70000 Finance
5 Peter 45000 v
Table: Departments
0 Department
1 HR
2 Finance
3 Tv
Please write a stored procedure named GetAverageSalaryByDepartment that accepts a department
1D as a parameter and returns the average salary of employees in that department. If the department
1D is invalid, the procedure should return an error message saying “the department does not exist”.
Note: You can assume that the department IDs are unique and refer to valid departments in the
Departments table.
Please provide the SQL code for the GetAverageSalaryByDepartment stored procedure,Question-2
Scenario: ABC Company uses a Customer Relationship Management (CRM) system to track customer
information. The customer table contains details such as customer names, email addresses, and
subscription status. The company wants to automatically send an email whenever a customer's
subscription status is set to "Active." They plan to achieve this by creating a trigger.
Question: ABC Company wants to create a trigger on the customer table to automatically send an
email when a customer's subscription status is set to "Active." How should the trigger be created,
and what operations should it include?