select * from table 
if @@count>0 then
insert into table values(,,,)
end if

解决方案 »

  1.   

    declare @count int
    select count(*) from table 
    if @count==0 then 
    insert into table......
    end if
      

  2.   

    有种做法就是将提交语句保存到数据库中。再次提交时,只要检查这个语句是否存在就可以判定了。这种做法一般用于业务逻辑的回滚。还有一种也是这么做的,设置一个流程表,如果提交了,流程表里记录下,下次提交前或者该业务处理前select下就可以了。
      

  3.   

    iif exists(select keyfield from table where keyfield='now value')
    --存在数据则更新
    begin 
    update  table set  keyfield='now value'
    end 
    else
    --新数据则插入
    begin
    insert into  table(keyfield) values('now value')
    end 
      

  4.   

    if exists(select keyfield from table where keyfield='now value')
    return