Knowee
Questions
Features
Study Tools

(a) Create a trigger, which verify that updated salary of employee must begreater than his/her previous salary(b) Create a trigger, which verify that for the department 2, the number ofemployees should not exceed than 5.

Question

(a) Create a trigger, which verify that updated salary of employee must begreater than his/her previous salary(b) Create a trigger, which verify that for the department 2, the number ofemployees should not exceed than 5.

🧐 Not the exact question you are looking for?Go ask a question

Solution

It seems like you're asking for SQL triggers. Here's how you can create them:

(a) To create a trigger that verifies that the updated salary of an employee is greater than his/her previous salary, you can use the following SQL code:

CREATE TRIGGER salary_check BEFORE UPDATE ON employees
FOR EACH ROW
BEGIN
   IF NEW.salary <= OLD.salary THEN
      SIGNAL SQLSTATE '45000'
         SET MESSAGE_TEXT = 'Error: Updated salary must be greater than the previous salary.';
   END IF;
END;

This trigger is activated before an update on the employees table. It compares the new salary (NEW.salary) with the old salary (OLD.salary). If the new salary is less than or equal to the old salary, it raises an error.

(b) To create a trigger that verifies that for department 2, the number of employees should not exceed 5, you can use the following SQL code:

CREATE TRIGGER employee_count_check AFTER INSERT ON employees
FOR EACH ROW
BEGIN
   IF NEW.department_id = 2 AND 
      (SELECT COUNT(*) FROM employees WHERE department_id = 2) > 5 THEN
      SIGNAL SQLSTATE '45000'
         SET MESSAGE_TEXT = 'Error: Number of employees in department 2 should not exceed 5.';
   END IF;
END;

This trigger is activated after an insert on the employees table. It checks if the new employee's department is 2 and if the total number of employees in department 2 exceeds 5. If both conditions are met, it raises an error.

Please note that the actual syntax might vary depending on the SQL dialect you're using. The above examples are written in MySQL.

This problem has been solved

Similar Questions

Problem statementSend feedbackSuppose you have a list of employees in a company, and each employee is represented as an object with the following properties:"id" - a unique identifier for the employee"name" - the employee's name"department" - the department the employee works in"salary" - the employee's current salaryObjectives:You want to make a modification to the list of employees to reflect a recent company-wide salary increase. You have been provided with the following information:Salaries for employees in the "sales" department should be increased by 10%.Salaries for employees in the "engineering" department should be increased by 15%.Salaries for employees in all other departments should be increased by 5%.You need to write a function "increaseSalaries" that takes an array of employee objects and returns a new array of employee objects where each employee's salary has been updated based on their department. The original array of employees should be left unchanged.

For the Employee Class Program in this tutorial, what if we need the capability to update the salary for employees? What information is needed to perform this task, and what code segment implements obtaining it in a method?a.)Employees file information and the new salarydef upd_salary(): employees = read_employees() new_sal = input("Enter the new salary of the employee: ")b.)The new salarydef upd_salary(employees): new_sal = input("Enter the new salary of the employee: ")c.)Employee iddef upd_salary(employees): empid = input("Enter the employee ID: ")d.)Employee id and the new salarydef upd_salary(employees): empid = input("Enter the employee ID: ") new_sal = input("Enter the new salary of the employee: ")

In PostgreSQL, create a PL/pgSQL block that defines a procedure namedupdate_employee_salary which takes two parameters: employee_id and new_salary. This procedure should update the salary ofthe employee with the given employee_id to the new salary value. Assume “employee” table with fields – eid, ename and salary

Write SQL QueriesEmployee TableDepartment Table1. Get the list of employees whose salary is more than 20K and are in HR department.2. Get the salary being paid to each Department.3. Get the employees with the third highest salary.4. Name and designation of the employees who don't have any manager

Create PL/pgSQL procedure for the increment of employees where in salary less than 35000 will get hike of 15% in their previoussalary and other will get 10% hike in their previous salary. Using following schema, Employees (id, name, department, salary)call the procedure by id and print employee’s name with their updated salary

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.