with adoquery1 do
begin
  close;
  sql.clear;
  sql.text := 'select id from workcount where id = :1';
  parameters.parambyname('1').value := ?
  open;
  if recordcount = 0 then
  begin
      // 记录没找到;插入
  end
  else exit; //已经存在;退出;
end;

解决方案 »

  1.   

    1.可以把ID设为主键。
    2.使用语句:
    if not exists(select * from tablename where id=@id)
    begin
    insert into values(@id,@a,@b,@c)
    end
      

  2.   

    with adoquery1 do
      begin
       active:=false
       sql.clear;
       sql.add('select id from table_name where id='+#39+id+#39)
       open
       if eof then
        //插入数据
      end
      

  3.   

    if (select count(*) from workcount where id = @id) = 0 
      insert into workcount (id,a,b,c) values (@id,@a,@b,@c)