create table t(id int,[date] datetime,a varchar(10))
insert into t select 1,'2005-01-01','aa'
gocreate trigger cfq on t
for update
asif @@rowcount=0 returnupdate a set a.[date]=getdate() from t a,inserted b where a.id=b.id
goupdate t set a='bb' where id=1
goselect * from t
drop trigger cfq
drop table a--这样?

解决方案 »

  1.   

    CREATE TRIGGER [test] ON TABLENAME 
    FOR  UPDATE 
    AS

    if (update(UPDATEFIELD))
    begin
    declare @id int
    select @id = id from inserted
    update TABLENAME set UPDATEDATE=getdate() where id=@id
    end
    deleted 和 inserted 是逻辑(概念)表。这些表在结构上类似于定义触发器的表(也就是在其中尝试用户操作的表);这些表用于保存用户操作可能更改的行的旧值或新值。
      

  2.   

    inserted表里边复制了当前insert或update的内容可以在触发器里使用