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