日期:2014-05-18  浏览次数:20367 次

如何获取表中行最新修改的时间
各位高手请问,当表中的行一修改时,如何才能马上获取他修改的时间,同时将获取到的时间放入到行中的最新修改( "LastUpdateTime ")这一列中!

------解决方案--------------------
写触发器;
create table t1
(
FID int,
FDate datetime
)

create trigger tr_t1 on t1
for insert,update
as

update t1
set Fdate = getdate()
where FID in (select FId from inserted)
------解决方案--------------------
create table T(ID int not null primary key, Name varchar(10), LastUpdateTime datetime)
insert T select 1, 'AA ', NULL
insert T select 2, 'BB ', NULL
insert T select 3, 'CC ', NULL

create trigger tr on T
for update
as
update T set LastUpdateTime=getdate()
from deleted B
where T.ID=B.ID

update T set Name= 'BBB '
where ID=2

select * from T