.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.
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);
.schema table-name
.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);