Small. Fast. Reliable.
Choose any three.

Information Schema

If you have question regarding this information or if I have something wrong please email me at vbsqliteNOSPAM@NOSPAMag-software.com (remove the NOSPAM's)

The information schema consists of a set of views that contain information about the objects defined in the current database. The information schema is defined in the SQL standard and can therefore be expected to be portable and remain stable. (Compare PostgreSQL's information schema documentation.)

sqlite_master is the base table where schema information is stored, these views query this table. SQLite doesn't support the idea of different owners of objects so the naming convention for the INFORMATION_SCHEMA views are INFORMATION_SCHEMA_OBJECTNAME.

INFORMATION_SCHEMA_TABLES

This view describes all tables and views defined in the current database. It has these columns:

Name Description
TABLE_CATALOG Name of the database that contains the table (always 'main')
TABLE_SCHEMA Name of the schema that contains the table (always 'sqlite')
TABLE_NAME Name of the table or view
TABLE_TYPE Type of the table: BASE TABLE for a persistent base table (the normal table type), BASE VIEW for a view, or TEMPORARY TABLE for a temporary table and TEMPORARY VIEW for a temporary view.
TABLE_SOURCE The SQL script with which the object was created.
CREATE VIEW INFORMATION_SCHEMA_TABLES AS
    SELECT * FROM (
        SELECT 'main'     AS TABLE_CATALOG,
               'sqlite'   AS TABLE_SCHEMA,
               tbl_name   AS TABLE_NAME,
               CASE WHEN type = 'table' THEN 'BASE TABLE'
                    WHEN type = 'view'  THEN 'VIEW'
               END        AS TABLE_TYPE,
               sql        AS TABLE_SOURCE
        FROM   sqlite_master
        WHERE  type IN ('table', 'view')
               AND tbl_name NOT LIKE 'INFORMATION_SCHEMA_%'
        UNION
        SELECT 'main'     AS TABLE_CATALOG,
               'sqlite'   AS TABLE_SCHEMA,
               tbl_name   AS TABLE_NAME,
               CASE WHEN type = 'table' THEN 'TEMPORARY TABLE'
                    WHEN type = 'view'  THEN 'TEMPORARY VIEW'
               END        AS TABLE_TYPE,
               sql        AS TABLE_SOURCE
        FROM   sqlite_temp_master
        WHERE  type IN ('table', 'view')
               AND tbl_name NOT LIKE 'INFORMATION_SCHEMA_%'
    ) ORDER BY TABLE_TYPE, TABLE_NAME;

Note, 12 Jan 2006: I reformatted this page so it was actually possible to read it, but I did not debug the SQL code given. As stated, it does not work; any query on the view gives the error "no such table: sqlite_temp_master". If you don't use temporary tables you can just rip out the second inner SELECT (which then renders the outer SELECT unnecessary):

CREATE VIEW INFORMATION_SCHEMA_TABLES AS
    SELECT 'main'     AS TABLE_CATALOG,
           'sqlite'   AS TABLE_SCHEMA,
           tbl_name   AS TABLE_NAME,
           CASE WHEN type = 'table' THEN 'BASE TABLE'
                WHEN type = 'view'  THEN 'VIEW'
           END        AS TABLE_TYPE,
           sql        AS TABLE_SOURCE
    FROM   sqlite_master
    WHERE  type IN ('table', 'view')
           AND tbl_name NOT LIKE 'INFORMATION_SCHEMA_%'
    ORDER BY TABLE_TYPE, TABLE_NAME;