sql 语句 insert into 怎么限制同一条数据只写入一次?求指点!!!

解决方案 »

  1.   

    比如,我数据库里有四个字段n1,n2,n2,stage
    如果对应的数据是。。1,2,3,98.
    我现在的问题是,每刷一次就会插入这一组数据好多次我就想如果与上面那条数据一样的,,就不能再写入
    谢谢指点
      

  2.   

    可以考虑一下 “Instead of”触发器
      

  3.   

    可以在插入前,加if not exists()判断..if not exists(select 1 from [表名] where n1=.. and n2=.. and stage=..)
    begin
      insert into [表名](n1,n2,stage) ...
    end
      

  4.   

    给表的字段 n1,n2,n2,stage 建立唯一唯一索引,并忽略重复键.
      

  5.   

    if not exits(select * from t where n1='x1' and n2='x2' and n3='x3' and stage='x_stage')
    begin
    insert into t (n1,n2,n3,stage)
    select x1,x2,x3,x_stage
    end大致这个意思吧
      

  6.   

    insert into t (n1,n2,n3,stage)
    select x1,x2,x3,x_stage
    except
    select n1,n2,n3,stage from t
      

  7.   

    if not exists(select 1 from [表名] where n1=.. and n2=.. and stage=..)
    begin
      insert into [表名](n1,n2,stage) ...
    end