Discussion:
How to check whether a table is empty or not in sqlite.
bhaskarReddy
13 years ago
Permalink
HI Friends,

How to check whether a table is empty or not. If a table is empty, i
want to do some logic. If not another logic.


Can any one tell me how to check if table in a data base is empty
or not, using sqlite3.


Regards,
Bhaskar.
--
View this message in context: http://old.nabble.com/How-to-check-whether-a-table-is-empty-or-not-in-sqlite.-tp33314679p33314679.html
Sent from the SQLite mailing list archive at Nabble.com.
Igor Tandetnik
13 years ago
Permalink
Post by bhaskarReddy
How to check whether a table is empty or not. If a table is empty, i
want to do some logic. If not another logic.
select exists (select 1 from MyTable);
--
Igor Tandetnik
Simon Slavin
13 years ago
Permalink
Post by Igor Tandetnik
Post by bhaskarReddy
How to check whether a table is empty or not. If a table is empty, i
want to do some logic. If not another logic.
select exists (select 1 from MyTable);
Or

SELECT COUNT(*) from MyTable

which will give you 0 if the table is empty, and some other integer otherwise.

Simon.
Jay A. Kreibich
13 years ago
Permalink
Post by Simon Slavin
Post by Igor Tandetnik
Post by bhaskarReddy
How to check whether a table is empty or not. If a table is empty, i
want to do some logic. If not another logic.
select exists (select 1 from MyTable);
SELECT COUNT(*) from MyTable
For a large table, that might take some time.

-j
--
Jay A. Kreibich < J A Y @ K R E I B I.C H >

"Intelligence is like underwear: it is important that you have it,
but showing it to the wrong people has the tendency to make them
feel uncomfortable." -- Angela Johnson
Kit
13 years ago
Permalink
Post by Igor Tandetnik
       How to check whether a table is empty or not. If a table is empty, i
want to do some logic. If not another logic.
select exists (select 1 from MyTable);
SELECT exists(SELECT 1 FROM MyTable LIMIT 1);
--
Kit
Igor Tandetnik
13 years ago
Permalink
Post by Kit
Post by Igor Tandetnik
Post by bhaskarReddy
How to check whether a table is empty or not. If a table is empty, i
want to do some logic. If not another logic.
select exists (select 1 from MyTable);
SELECT exists(SELECT 1 FROM MyTable LIMIT 1);
exists() predicate is smart enough to stop as soon as the first row is
retrieved. LIMIT 1 clause is redundant, though harmless.
--
Igor Tandetnik
Loading...