Back to lessons

Hosting Operations

Show One SQLite Table Schema

You need to inspect the schema for one SQLite table.

Command

sqlite3 app.db ".schema users"

What changed

Nothing changes. The command prints schema statements for the selected table.

Danger

safe

When to use it

Use before writing ad hoc SQL against a table you do not know well.

When not to use it

Do not use it as a migration history; it shows current schema, not how it got there.

Undo or recovery

No undo needed because this command is read-only.

Expected output

CREATE TABLE and related index statements for the users table.

demo script

Disposable terminal steps

  1. sqlite3 app.db ".tables"
  2. sqlite3 app.db ".schema users"

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ sqlite3 app.db ".tables"
events  orders  schema_migrations  users
::exit-code::0
$ sqlite3 app.db ".schema users"
CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  email TEXT NOT NULL,
  created_at TEXT NOT NULL
);
CREATE UNIQUE INDEX idx_users_email ON users(email);
::exit-code::0

YouTube Short

Check one table schema.

Before guessing column names, ask SQLite for the table schema and indexes directly.

LinkedIn hook

A failed query is often just a wrong assumption about column names.

Question: Do you inspect table schema before writing incident queries?

experiments

A/B tests to run

Metric: save_rate

A: Guess less.

B: Check schema first.