SQLite Schema Information Metadata

后端 未结 7 1049
终归单人心
终归单人心 2020-11-27 03:46

I need to get column names and their tables in a SQLite database. What I need is a resultset with 2 columns: table_name | column_name.

In MySQL, I\'m a

7条回答
  •  旧时难觅i
    2020-11-27 04:18

    You've basically named the solution in your question.

    To get a list of tables (and views), query sqlite_master as in

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

    (see the SQLite FAQ)

    To get information about the columns in a specific table, use PRAGMA table_info(table-name); as explained in the SQLite PRAGMA documentation.

    I don't know of any way to get tablename|columnname returned as the result of a single query. I don't believe SQLite supports this. Your best bet is probably to use the two methods together to return the information you're looking for - first get the list of tables using sqlite_master, then loop through them to get their columns using PRAGMA table_info().

提交回复
热议问题