表中某列被修改后触发器SQL例子

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 oswica 的 blog


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
--问题:不能获得修改前的值???

本文关键:表中某列被修改后触发器SQL例子
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top