Search notes:

SQLite shell: .schema

The SQLite shell command .schema dumps an SQLite database's schema.
.schema %pattern% dumps the tables that match %pattern%.
.schema prints the SQL statement that was used to create a table or view. Thus, the output might be somewhat hard to read, especially if one simply wants to query a table's or view's column names and types.
In such a case, the alternative pragma table_info('<table name>') does exactly that.

Demonstration

The following example demonstrates .schema:

Create schema

First, we need a schema:
create table tab_one (
   col_1  integer,
   col_2  text,
   col_3  text
);

create table tab_two (
   v1,
   v2
);

create table tab_three (
   c1    integer primary key,
   c2    text
);

create index ix_tab_two on tab_two(v2);

.schema

Show the enitre schema:
.schema
--
-- CREATE TABLE tab_one (
--    col_1  integer,
--    col_2  text,
--    col_3  text
-- );
-- CREATE TABLE tab_two (
--    v1,
--    v2
-- );
-- CREATE TABLE tab_three (
--    c1    integer primary key,
--    c2    text
-- );
-- CREATE INDEX ix_tab_two on tab_two(v2);
Github repository about-sqlite, path: /shell/schema/schema.sql

.schema table-name

Display the create table statement for a specific table:
.schema tab_two
--
-- CREATE TABLE tab_two (
--    v1,
--    v2
-- );
-- CREATE INDEX ix_tab_two on tab_two(v2);

.schema %pattern%

Finally, display the statements for the tables that match a pattern:
.schema %tab_t%
--
-- CREATE TABLE tab_two (
--    v1,
--    v2
-- );
-- CREATE TABLE tab_three (
--    c1    integer primary key,
--    c2    text
-- );
-- CREATE INDEX ix_tab_two on tab_two(v2);

See also

The internal table sqlite_master.
.fullschema
SQLite shell

Index