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.
_______________________________________________
sqlite-users mailing list
sqlite...@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
select exists (select 1 from MyTable);
--
Igor Tandetnik
> bhaskarReddy <uni...@gmail.com> wrote:
>> 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.
> 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
SELECT exists(SELECT 1 FROM MyTable LIMIT 1);
--
Kit
exists() predicate is smart enough to stop as soon as the first row is
retrieved. LIMIT 1 clause is redundant, though harmless.
--
Igor Tandetnik