Skip to main content

Importing Data

Importing is one of the fastest ways to get real data into SQLite for exploration and learning.

The core CLI workflow is: choose format, import file, verify results.

Core Concepts

flowchart LR
A[Prepare CSV file] --> B[Open database]
B --> C[Set .mode csv]
C --> D[Run .import file table]
D --> E[Validate with SELECT]
StepCommand
Set input format.mode csv
Import file.import data.csv people
Verify dataSELECT count(*) FROM people;

Code Examples

-- In sqlite3 shell: set CSV mode for import.
.mode csv

-- Import data.csv into table people.
-- Table should already exist with matching columns.
.import data.csv people
Expected output
Usually no success text; errors are printed if import fails.
-- Validate how many rows were imported.
SELECT count(*) AS row_count FROM people;
row_count
e.g. 100

SQLite-Specific Nuances

SQLite Nuance

.import behavior is controlled by CLI settings like .mode and separator settings.

These are shell settings, not SQL syntax.

Common Pitfalls / Best Practices

Pitfall

Importing into a table with incompatible column order or count.

This can produce errors or wrong column placement.

Best Practice

Run a quick row-count query right after import to confirm expected volume.

Quick Challenge

After importing students.csv into students, write a query to verify imported row count.

View Solution
SELECT count(*) AS row_count FROM students;
row_count
e.g. expected number of CSV rows