Is there an SQLite equivalent to MySQL's DESCRIBE [table]?
The SQLite command line utility has a .schema TABLENAME
command that shows you the create statements.
PRAGMA table_info([tablename]);
Are you looking for the SQL used to generate a table? For that, you can query the sqlite_schema
table:
sqlite> CREATE TABLE foo (bar INT, quux TEXT);
sqlite> SELECT * FROM sqlite_schema;
table|foo|foo|2|CREATE TABLE foo (bar INT, quux TEXT)
sqlite> SELECT sql FROM sqlite_schema WHERE name = 'foo';
CREATE TABLE foo (bar INT, quux TEXT)
Alternative Names
The schema table can always be referenced using the name
sqlite_schema
, especially if qualifed by the schema name likemain.sqlite_schema
ortemp.sqlite_schema
. But for historical compatibility, some alternative names are also recognized, including:
sqlite_master
sqlite_temp_schema
sqlite_temp_master
Alternatives (2) and (3) only work for the TEMP database associated with each database connection, but alternative (1) works anywhere.
To see all tables:
.tables
To see a particular table:
.schema [tablename]