Subject | Re: [ib-support] How can I cjeck if a table is empty? |
---|---|
Author | Arno Brinkman |
Post date | 2003-05-04T17:46:14Z |
Hi,
Just run a query 'SELECT * FROM MyTable' and try to fetch 1 row.
in Delphi (untested) result is False when Empty:
Result := False;
With TIB_Query.Create(nil) do
begin
IB_Connection := ADatabaseConnection;
SQL.Text := 'SELECT * FROM MyTable';
Open;
if not(EOF) then
begin
Result := True;
end;
Close;
end;
Regards,
Arno
> I am using InterBase 6.0.2.Yes, a Count(*) expensive and unneeded.
>
> How can I check if a table is empty?
>
> I have a table named MyTable with a field named XXX.
>
> I have been using the instruction below to check if MyTable is empty
> or not:
>
>
> "Select Count(XXX) as NumRecords from MyTable"
>
>
> If NumRecords = 0 then MyTable is empty.
>
>
> Is there another way to do check if a table is empty?
Just run a query 'SELECT * FROM MyTable' and try to fetch 1 row.
in Delphi (untested) result is False when Empty:
Result := False;
With TIB_Query.Create(nil) do
begin
IB_Connection := ADatabaseConnection;
SQL.Text := 'SELECT * FROM MyTable';
Open;
if not(EOF) then
begin
Result := True;
end;
Close;
end;
Regards,
Arno