假如我对一个表在新增一条记录时,当新增的字段A 的值等于某一个值时,字段B 就相应的对应另外一个值,不想每次用手去录入,想用触发器无法实现,不知是否可行。

解决方案 »

  1.   

    create trigger my_trig on tb for insert
    as
    begin
      if exists(select 1 from inserted where a = '某一个值')
         update tb set b = '相应的对应另外一个值' where 关键字 = (select 关键字 from inserted)
    end
      

  2.   

    如果是多记录插入,这个会报错,把 where 关键字 = 改成 where 关键字 in
      

  3.   

    可以用GUID啊,永远不会重复的。