Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

SQLite Tutorial

SQLite HOME SQLite Intro SQLite Get Started

SQLite SQL

SQLite SQL SQLite SELECT SQLite SELECT DISTINCT SQLite WHERE SQLite ORDER BY SQLite AND SQLite OR SQLite NOT SQLite INSERT INTO SQLite NULL Values SQLite UPDATE SQLite DELETE SQLite LIMIT SQLite Aggregate SQLite MIN() and MAX() SQLite COUNT() SQLite SUM() SQLite AVG() SQLite LIKE SQLite Wildcards SQLite GLOB SQLite IN SQLite BETWEEN SQLite Aliases SQLite Joins SQLite INNER JOIN SQLite LEFT JOIN SQLite RIGHT JOIN SQLite FULL JOIN SQLite CROSS JOIN SQLite Self Join SQLite UNION SQLite UNION ALL SQLite INTERSECT and EXCEPT SQLite GROUP BY SQLite HAVING SQLite EXISTS SQLite Subqueries SQLite INSERT INTO SELECT SQLite CASE SQLite NULL Functions SQLite Comments SQLite Operators

SQLite Advanced

SQLite UPSERT SQLite RETURNING SQLite WITH (CTE) SQLite Window Functions SQLite JSON

SQLite Database

SQLite Create DB SQLite Attach DB SQLite Create Table SQLite Drop Table SQLite Alter Table SQLite Data Types SQLite STRICT Tables SQLite Constraints SQLite NOT NULL SQLite UNIQUE SQLite PRIMARY KEY SQLite FOREIGN KEY SQLite CHECK SQLite DEFAULT SQLite AUTOINCREMENT SQLite Generated Columns SQLite Create Index SQLite Views SQLite Triggers SQLite Dates SQLite Transactions SQLite PRAGMA SQLite Injection

SQLite Tools

SQLite Command Line SQLite Import and Export SQLite with Python

SQLite References

SQLite Functions

SQLite Exercises

SQLite Editor SQLite Quiz SQLite Exercises

SQLite Command Line


Share

The sqlite3 Program

sqlite3 is the command line program for SQLite. With it, you can open a database, run SQL statements and look at the result. Read how to install it in the SQLite Get Started chapter.

Start sqlite3 with the name of a database file:

sqlite3 northwind.db

You get the prompt sqlite>, where you can type SQL statements. End each statement with a semicolon. If a statement continues on the next line, the prompt changes to ...>.


Dot Commands

Commands that start with a dot are special commands for sqlite3, not SQL. They do not end with a semicolon:

CommandDescription
.helpShows all the dot commands
.open FILEOpens a database file, and creates it if it does not exist
.tablesLists the tables
.schema TABLEShows the CREATE statement of a table
.headers onShows the column names in the result
.mode MODESets the output format, like list, column, box, table, csv, json or markdown
.read FILERuns the SQL statements in a file
.output FILEWrites the results to a file. .output stdout writes to the screen again
.import FILE TABLEImports data from a file into a table
.dumpWrites the whole database as SQL statements
.databasesLists the attached databases
.quitCloses sqlite3


Easy to Read Results

By default, sqlite3 shows each record on one line, with the values separated by |, and without the column names:

sqlite> SELECT * FROM Shippers;
1|Speedy Express|(503) 555-9831
2|United Package|(503) 555-3199
3|Federal Shipping|(503) 555-9931

These two commands make the results much easier to read:

sqlite> .headers on
sqlite> .mode box
sqlite> SELECT * FROM Shippers;
┌───────────┬──────────────────┬────────────────┐
│ ShipperID │   ShipperName    │     Phone      │
├───────────┼──────────────────┼────────────────┤
│ 1         │ Speedy Express   │ (503) 555-9831 │
│ 2         │ United Package   │ (503) 555-3199 │
│ 3         │ Federal Shipping │ (503) 555-9931 │
└───────────┴──────────────────┴────────────────┘

.headers on shows the column names, and .mode box draws lines around the values.


Run SQL Without the Prompt

You can give sqlite3 an SQL statement directly. It prints the result, and stops:

sqlite3 northwind.db "SELECT COUNT(*) FROM Customers;"
91

You can also save SQL statements in a file, and run them all at once. Here is a file named script.sql, with two statements:

SELECT COUNT(*) FROM Customers;

SELECT CustomerName FROM Customers
WHERE Country = 'UK';

Run the file like this. The results of the statements are printed one after the other:

sqlite3 northwind.db < script.sql
91
Around the Horn
B's Beverages
Consolidated Holdings
Eastern Connection
Island Trading
North/South
Seven Seas Imports

Note: Windows PowerShell does not support <. There, write sqlite3 northwind.db ".read script.sql" instead.




Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.