Mahesh Babu
Mahesh Babu

Reputation: 3433

How to get list of all the tables in sqlite programmatically

How can I get the list of all the available tables in sqlite programmatically?

Upvotes: 22

Views: 35908

Answers (6)

Kudakwashe Mafutah
Kudakwashe Mafutah

Reputation: 31

"SELECT name FROM sqlite_master WHERE name NOT LIKE 'sqlite_%'"

or

'SELECT * FROM sqlite_sequence WHERE name NOT LIKE "sqlite_%"'

Upvotes: 0

DailyLearner
DailyLearner

Reputation: 2354

To get only the names of the table run the below query.

SELECT name FROM sqlite_master WHERE type='table';

Running the above query on Chinook_Sqlite.sqlite produce the following output:

sqlite> SELECT name FROM sqlite_master WHERE type='table';
Album
Artist
Customer
Employee
Genre
Invoice
InvoiceLine
MediaType
Playlist
PlaylistTrack
Track
sqlite>

Upvotes: 1

Raccoon_Alert
Raccoon_Alert

Reputation: 1


con = sqlite3.connect('db.sqlite')
cur = con.cursor()

cur.execute('''
    SELECT tbl_name
    FROM sqlite_master
    WHERE type = 'table';
''')

print(cur.fetchall())

Upvotes: 0

Mitesh Khatri
Mitesh Khatri

Reputation: 3955

try this :

SELECT * FROM sqlite_master where type='table';

Upvotes: 43

M-sAnNan
M-sAnNan

Reputation: 804

worked for me

    SELECT * FROM sqlite_master where type='table'

Upvotes: 3

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

Use the below sql statement to get list of all table in sqllite data base

SELECT * FROM dbname.sqlite_master WHERE type='table';

The same question asked before on StackOverFlow.

How to list the tables in an SQLite database file that was opened with ATTACH?

Upvotes: 12

Related Questions