Reputation: 3433
How can I get the list of all the available tables in sqlite programmatically?
Upvotes: 22
Views: 35908
Reputation: 31
"SELECT name FROM sqlite_master WHERE name NOT LIKE 'sqlite_%'"
or
'SELECT * FROM sqlite_sequence WHERE name NOT LIKE "sqlite_%"'
Upvotes: 0
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
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
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