欢迎光临
我们一直在努力

表中某列被修改后触发器SQL例子-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

create table [test] (
 [fid] [int] identity (1, 1) not null ,
 [f1] [int] null ,
 [f2] [int] null ,
 [f3] [int] null ,
 constraint [pk_test] primary key  clustered
 (
  [fid]
 )  on [primary]
) on [primary]
go

alter trigger updatetest on [dbo].[test]
for insert, update, delete
as
begin
 declare @f1 int,
  @fid int,
  @oldf1 int
 if update(f1)
 begin
  select @oldf1=f1 from test where fid in (select fid from inserted)
  select @fid=fid,@f1=f1 from inserted
  print fid = + convert(varchar(10),@fid)
  print oldf1 = + convert(varchar(10),@oldf1)
  print f1 = + convert(varchar(10),@f1)
 end
 
end

go

insert test(f1,f2,f3) values(1,2,3)
go
select * from test
go
update test set f1=11 where fid=1
go
–问题:不能获得修改前的值???

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 表中某列被修改后触发器SQL例子-数据库专栏,SQL Server
分享到: 更多 (0)

相关推荐

  • 暂无文章