Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all tables in a DB using SQLite

Tags:

sqlite

I can't seem to find documentation (that I understand) on how to list all tables in a database. I've tried the following:

SELECT * FROM .table;
SELECT * FROM .tab;
SELECT * FROM .db;
SELECT * FROM world.db;

None of them worked. I'm just learning SQL, so forgive my ignorance. :0)

like image 241
Mr.Syrax Avatar asked Mar 14 '14 15:03

Mr.Syrax


People also ask

How do I SELECT all tables in a database?

The easiest way to find all tables in SQL is to query the INFORMATION_SCHEMA views. You do this by specifying the information schema, then the “tables” view. Here's an example. SELECT table_name, table_schema, table_type FROM information_schema.

How many tables are there in SQLite database?

Maximum Number Of Tables In A Join SQLite does not support joins containing more than 64 tables. This limit arises from the fact that the SQLite code generator uses bitmaps with one bit per join-table in the query optimizer.

How show all tables in SQLite3 Python?

To list all tables in an SQLite3 database, you should query the sqlite_master table and then use the fetchall() to fetch the results from the SELECT statement. The sqlite_master is the master table in SQLite3, which stores all tables.


2 Answers

Try this:

SELECT * FROM sqlite_master WHERE type='table'
like image 103
fooser Avatar answered Nov 07 '22 11:11

fooser


If you are in interactive mode, you can use this:

.tables

Another method with extra information:

.schema

https://sqlite.org/cli.html#querying_the_database_schema

like image 30
Zombo Avatar answered Nov 07 '22 09:11

Zombo