update tablename
set field2=90.00
where field1='2002-6-8'

解决方案 »

  1.   

    以上只是例子,关键是我并不知道哪个主键值下的记录会更新,因此where field的值也就不知,请楼上赐教
      

  2.   

    有办法
    ---取得主键名,如列名为ID,则约束名一般为ID_pk
    ---取消约束
    alter table tablename with nocheck ID_pk
    update tablename
    set field2=90.00
    where field1='2002-6-8'
    ---继续插入
    ---恢复约束
    alter table tablename with check ID_pk
      

  3.   

    if exists (select 1` from tablename where where field1='2002-6-8')
      update tablename
        set field2=90.00
        where field1='2002-6-8'
    else
      insert into  tablename(field1,field2)
        values('2002-6-8',90.00)