Subject | Re: How can I check if a table is empty? |
---|---|
Author | mcrosman1957 |
Post date | 2003-05-05T15:00:39Z |
Hi, Arno.
Thank you for your answer.
I am developing a store procedure and a trigger in which I need to
check if a table is empty or not.
I have defined a store procedure local variable NumRecods as INTEGER
I have tought to use the instruction
Select Count(xxx) from MyTable
INTO :NumRecords
Is there a better way to do it ?
Thank you very much.
Marcelo.
--- In ib-support@yahoogroups.com, "Arno Brinkman" <firebird@a...>
wrote:
Thank you for your answer.
I am developing a store procedure and a trigger in which I need to
check if a table is empty or not.
I have defined a store procedure local variable NumRecods as INTEGER
I have tought to use the instruction
Select Count(xxx) from MyTable
INTO :NumRecords
Is there a better way to do it ?
Thank you very much.
Marcelo.
--- In ib-support@yahoogroups.com, "Arno Brinkman" <firebird@a...>
wrote:
> Hi,empty
>
> > I am using InterBase 6.0.2.
> >
> > 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
> > 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?
>
> Yes, a Count(*) expensive and unneeded.
>
> 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