SQL语句创建update触发器
条件:exam数据库中的表employee(emp_id,emp_name,gender,department,salary)创建update触发器up_salary,限...
条件:exam数据库中的表employee(emp_id,emp_name,gender,department,salary)创建update触发器up_salary,限制在exam数据库的employee表中的salary的变动不能超过原来工资的10%请问怎么写命令?
展开
1个回答
推荐于2017-05-19
展开全部
create trigger up_salary on employee INSTEAD OF update
as if update (salary)
begin
declare @newSalary numeric(10,2)
declare @oldSalary numeric(10,2)
select @newSalary = salary from updated
select @oldSalary = salary from employee where emp_id = (select emp_id from updated)
if @newSalary > @oldSalary * 1.1
print '工资变动不能超过原来工资的10%'
else
update employee set salary = @newSalary where emp_id = (select emp_id from updated)
end
go
as if update (salary)
begin
declare @newSalary numeric(10,2)
declare @oldSalary numeric(10,2)
select @newSalary = salary from updated
select @oldSalary = salary from employee where emp_id = (select emp_id from updated)
if @newSalary > @oldSalary * 1.1
print '工资变动不能超过原来工资的10%'
else
update employee set salary = @newSalary where emp_id = (select emp_id from updated)
end
go
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询