如何判断列中的数据是否已经更改,如果更改了就触发触发器?
假如表名为jiazu,字段有组别,项目,比赛成绩,排名组别字段中有man,wom项目有100,200当比赛成绩输入数据后,就激活自动排名?求怎么写,急怎么写触发器...
假如表名为jiazu,字段有组别,项目,比赛成绩,排名
组别字段中有man,wom
项目有100,200
当比赛成绩输入数据后,就激活自动排名?
求怎么写,急
怎么写触发器 展开
组别字段中有man,wom
项目有100,200
当比赛成绩输入数据后,就激活自动排名?
求怎么写,急
怎么写触发器 展开
1个回答
展开全部
create table info(_id int unique identity(1,1),grade decimal(10,2);
go
insert into info(grade)values(10);
go
create trigger info_update_trigger on info for update
as
begin
declare @old_grade decimal(10,2), @new_grade decimal(10,2);
select @new_grade = n.grade,
@old_grade = o.grade
from inserted as n
inner join deleted as o on o._id=n._id;
if(@new_grade != @old_grade )
begin
print('old grade=' + convert(varchar,@old_grade));
print('new grade=' + convert(varchar,@new_grade));
print('log it');
end
end
go
update info set grade = grade + 1 where _id=1
go
insert into info(grade)values(10);
go
create trigger info_update_trigger on info for update
as
begin
declare @old_grade decimal(10,2), @new_grade decimal(10,2);
select @new_grade = n.grade,
@old_grade = o.grade
from inserted as n
inner join deleted as o on o._id=n._id;
if(@new_grade != @old_grade )
begin
print('old grade=' + convert(varchar,@old_grade));
print('new grade=' + convert(varchar,@new_grade));
print('log it');
end
end
go
update info set grade = grade + 1 where _id=1
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询