Database commands
D1 supports a number of database-level commands that allow you to list tables, indexes, and inspect the schema for a given table or index.
 Commands
You can execute any of these commands via the D1 console in the Cloudflare dashboard, wrangler d1 execute, or with the D1 client API.
PRAGMA table_list
Lists the tables in the database. This includes the system tables maintained by D1.
PRAGMA table_info(TABLE_NAME)
Shows the schema (columns, types, null, default values) for the given TABLE_NAME.
PRAGMA table_xinfo(TABLE_NAME)
Similar to PRAGMA table_info(TABLE_NAME) but also includes generated columns.
PRAGMA index_list(TABLE_NAME)
Show the indexes for the given TABLE_NAME.
PRAGMA index_info(INDEX_NAME)
Show the indexed column(s) for the given INDEX_NAME.
Query sqlite_master
You can also query the sqlite_master table to show all tables, indexes, and the original SQL used to generate them:
 Related resources
- Learn how to create indexes in D1.
- Use D1’s JSON functions to query JSON data.
- Use wrangler devto run your Worker and D1 locally and debug issues before deploying.