在BDE中可以这样做(你的数据表里应该建有主键)。
procedure TForm1.Button1Click(Sender: TObject);
begin
Query1.SQL.Clear;
Query1.SQL := Memo1.Lines;
try
if (RadioButton1.Checked) then
Query1.ExecSQL
else
Query1.Open;
except
on E:EDBEngineError do
if E.Errors[0].ErrorCode = 9729 then
ShowMessage('主键重复');
end;
end;