A database in one file

Create a SQLite database file

Create a real SQLite database by writing its first schema instead of making an empty placeholder file.

8 minute lesson

~~~

Opening a new path does not immediately write a database file. SQLite creates the real file when you write its first schema or data.

Open the database:

sqlite3 notes.db

Create its first table:

CREATE TABLE notes (
  id INTEGER PRIMARY KEY,
  title TEXT NOT NULL
) STRICT;

Run .databases to see the full path, then leave with .quit. notes.db now contains a valid SQLite header and schema.

Do not use touch to create a database. It only creates a zero-byte placeholder. Also, do not treat an ordinary file copy as a safe backup while the database is active. We will make a consistent backup later.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →