Wednesday 16 October 2013

07. Create a trigger named Emp_Update_Trg that will restrict the updation of salary of an employee if the new salary is less than the previous salary in the EmployeeDetails table.

create trigger emp_UPdate_Trg
on employeeDetail After UpDATE
as
Begin
Declare @oldSal money
Declare @NewSal money
select @oldSal=salary from deleted
select @NewSal=Salary from Insertd
if @OldSal>@NewSal
begin
Rollback
print ('New salary cannot be less than the old salary')
end
end

No comments:

Post a Comment