Home » Blog » Topic » How to Search all Tables and Columns in SQLite Database?

How to Search all Tables and Columns in SQLite Database?

Andrew Jackson ~ Modified: August 17th, 2015 ~ ~ 1 Minute Reading

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

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #474 Score: 0
    Andrew Jackson
    Moderator
    1 pt

    Is there a way to search all the tables and columns of an Sqlite database? The only input would be the name of the SQLite DB file.

    #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])

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.