表中有两个字段,column1,column2  当column1的内容被改变时,触发器改变column2的内容

解决方案 »

  1.   


    create trigger trigger_name 
    on ta 
    for update 
    as 
    begin 
      if update(colname) and update(colname)...   end go
      

  2.   

    CREATE TRIGGER tri_test
     ON tb
    FOR UPDATE
    AS
       IF UPDATE(column1)
       BEGIN
          UPDATE a
             SET column2='xx'
          FROM tb AS a
             JOIN deleted AS d
            ON a.ID=d.ID
       END
    GO
      

  3.   

    没说太明白!
    补充下,,表中有两个字段,column1,column2  当column1的内容被变为空或时,column2改变为 ,column1的内容不为空或时,column2的内容改变为1
      

  4.   

    --> 测试数据: [s]
    create table [s] (column1 varchar(10),column2 varchar(10))
    insert into s select '12','aa'
    go
     
    create trigger tri_s on s for update
    as
    update s set column2 = case ltrim(isnull(column1,'')) when '' then '' else '1' end
    go
    update s set column1=' '
    select * from [s]
    update s set column1='3'
    select * from [s]
      

  5.   


    create trigger trigger_t ON 表
    for update
    as
    begin
      if exists(select * from inserted where column1='')
         update 表 set column2='' 
       else
        update 表 set column2=1
     end 
      

  6.   

    create trigger upd_table on table for update as
    if update(column1)
    begin
      if exists(select * from table a join inserted b on a.primaryid=b.primaryid where b.columns1='')
        update a set a.columns2='' from table a join inserted b on a.prid=b.prid where b.columns1=''
      else
         update a set a.columns2='1' from table a join inserted b on a.prid=b.prid where b.columns1<>''end