Home » Blog » Reply » Reply To: How to Search all Tables and Columns in SQLite Database?

Reply To: How to Search all Tables and Columns in SQLite Database?

Lincoln Burrows ~ Modified: August 18th, 2015 ~ ~ 1 Minute Reading

Home Forums How to Search all Tables and Columns in SQLite Database? Reply To: How to Search all Tables and Columns in SQLite Database?

#481 Score: 0
Lincoln Burrows
Moderator
16 pts

try this “SELECT name FROM sqlite_master WHERE type=’table'” to search all tables and columns in SQLite database.
For Example:
import sqlite3
import os
filename = …
with sqlite3.connect(filename) as conn:
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
cursor.execute(“SELECT name FROM sqlite_master WHERE type=’table'”)
for tablerow in cursor.fetchall():
table = tablerow[0]
cursor.execute(“SELECT * FROM {t}”.format(t = table))
for row in cursor:
for field in row.keys():
print(table, field, row[field])