IF EXISTS(SELECT 1 FROM inserted AS A JOIN deleted AS B ON A.tno=B.tno AND A.tsalary<B.tsalary) --小于
create trigger sal_nodecr on teacher update as if((select a.tsalary-b.tsalary from inserted,deleted where a.tno=b.tno)<0) begin raiserror('工资只能增加不能减少',16,1) rollback transaction end end
create trigger sal_nodec on teacher for update as if((select a.tsalary-b.tsalary from inserted a,deleted b where a.tno=b.tno)<0) begin raiserror('工资只能增加不能减少',16,1) rollback transaction end 改了之后的 呵呵
create trigger sal_nodecr on teacher for update as if exists(select 1 from inserted a join deleted b on a.tno=b.tno and a.tsalary<b.tsalary) begin raiserror('工资只能增加不能减少',16,1) rollback transaction end
FROM inserted AS A
JOIN deleted AS B
ON A.tno=B.tno
AND A.tsalary<B.tsalary)
--小于
on teacher
update
as
if((select a.tsalary-b.tsalary from inserted,deleted where a.tno=b.tno)<0)
begin
raiserror('工资只能增加不能减少',16,1)
rollback transaction
end
end
on teacher
for update
as
if((select a.tsalary-b.tsalary from inserted a,deleted b where a.tno=b.tno)<0)
begin
raiserror('工资只能增加不能减少',16,1)
rollback transaction
end
改了之后的 呵呵
on teacher
for update
as
if exists(select 1 from inserted a join deleted b on a.tno=b.tno and a.tsalary<b.tsalary)
begin
raiserror('工资只能增加不能减少',16,1)
rollback transaction
end