sqlsqliteschema

How do I get information_schema.columns (column information) for all tables?


I would like to query SQLite like:

SELECT table_name, column_name, data_type, is_nullable, ...
FROM information_schema.columns

PRAGMA table_info(table_name); just checks fields for one table. SELECT * FROM sqlite_master WHERE type = 'table'; just gets table names and creation statement.

Is there any way to "join" these two methods?


Solution

  • I know you don't want to hear this, but you're not going to be able to do the join from SQL with SQLite. The table_info pragma is not mapped to a standard query, but rather a virtual machine program hard-coded into the SQLite sources. That program only supports a single table. Full stop. :)

    If your needs are just testing, it shouldn't be too hard to write script to do what you want. Otherwise, you're going have to write this into your application. Either way, you'll be select the table name from sqlite_master using your sqlite_master query, make a SQL query from it using sqlite3_mprintf("pragma table_info(%s);",name), and prepare/execute that.