create trigger t
on 表
for update
as
if 修改了特定记录
begin
      操作另一个表
end
go

解决方案 »

  1.   

    --假如你的ID字段是主键,或有唯一约束。
    alter trigger trTest on test for update, delete as declare @id int
    set @id = 123
    if exists ( select 1 from deleted where id = 123 )
    update [某表]...
      

  2.   

    --alter -> create
    create trigger trTest on test for update, delete as declare @id int
    set @id = 123
    if exists ( select 1 from deleted where id = 123 )
    update [某表]...
      

  3.   

    谢谢!
    if exists ( select 1 from deleted where id = 123 )---是表示什么?
    我要的是:如果表test0中id=123的记录的title和content字段被改变,另一表test1的word和link字段也同时变化.
    不存在删除ID=123的记录的问题,只做update触发就可以了.
      

  4.   

    建立测试环境:
    insert a select 1,'a'
    union all select 2,'b'
    union all select 3,'c'
    select * from a insert b select 1,'a1'
    union all select 2,'b1'
    union all select 3,'c1'select * from a 
    select * from bcreate trigger tr1
    on a
    for update 
    as 
    if update(type)
    begin
    if exists (select * from deleted where id=2 and type='b')
    begin 
    update b set name='bb1' where id in (select id from inserted)
    end
    end
      

  5.   

    如果不是update(type)某一字段,而是update某一id号的记录的几个字段都要触发另一表的对应字段的改变,可以写为update(type1,type2.....)吗?
      

  6.   

    if exists ( select 1 from deleted where id = 123 )---是表示什么?
      表示是否存在,如果找到一笔纪录就是true,往下的模块就会执行,注意如果是null集合也是当存在,所以用这个也要确认不会出现没有还跑出一个null纪录来 FYI
      

  7.   

    如何判断某条记录被改变了,用if exists ( select 1 from deleted where id = 123 )吗?
    我只要改条记录被改变时触发update另一表,其他的不触发.
      

  8.   

    如果不是update(type)某一字段,而是update某一id号的记录的几个字段都要触发另一表的对应字段的改变,可以写为update(type1,type2.....)吗?
    是的,你可以这样写,没有问题
      

  9.   

    如果update的是一ntext字段,怎样从inserted表中取数据啊???
      

  10.   

    如果不是update(type)某一字段,而是update某一id号的记录的几个字段都要触发另一表的对应字段的改变,可以写为update(type1,type2.....)吗?
    是的,你可以这样写,没有问题
    ----------------------
    不行的