我 想做一个触发器,要求插入记录时发现某个字段的出现重复值在就回滚,不能用唯一索引,因为只有符合一定条件的记录才可以这么处理。、本身这个字段是可以有重复值的、谢谢大家。帮帮忙

解决方案 »

  1.   

    灵活应用inserted就行了
    declare @key 
    select 关键字=@key from inserted 
    if exists(select a.字段 from tablename ,inserted i  where a.字段=i.字段 and a.唯一索引<>i.唯一索引) return
    where 后面可灵活修改成你要效果
      

  2.   

    bbsftp(烨):我也是象你的方法做了。但是不管是发现重复值它都回滚。什么原因呢???
      

  3.   

    在使用insert 的时候判断一下该 值是否存在不就是了;
    if exists(select * from biao where 字段='aaaa') then
    begin
      
    end
    else
    begin
      insert into biao (字段) values('aaaa')
    end;
      

  4.   

    回复人: tgsh(大侠) ( ) 信誉:100  2005-05-27 14:17:00  得分: 0  
     
     
       bbsftp(烨):我也是象你的方法做了。但是不管是发现重复值它都回滚。什么原因呢???
    ---------------------------------------------
    你的触发器代码贴出来看看,应该是条件判断错了