Show Tables in SQLite Database in Python

后端 未结 1 1021
说谎
说谎 2021-01-05 22:05

I know this is a very basic question but for some reason I can\'t get past this one error. I\'m trying to show/put all the names of the tables in a database (named \'GData.d

相关标签:
1条回答
  • 2021-01-05 22:25

    The query to list tables in a Sqlite database:

    SELECT name FROM sqlite_master
    WHERE type='table'
    ORDER BY name;
    

    So your snippet becomes:

    con = sql.connect(r'/Users/linnk/Desktop/Results/GData.db')
    mycur = con.cursor() 
    mycur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;")
    available_table=(mycur.fetchall())
    

    See the Sqlite FAQ for more info.

    0 讨论(0)
提交回复
热议问题