SQLite Get Started
Try SQLite in Your Browser
The easiest way to start using SQLite is with our online editor.
It runs SQLite in your browser, so there is nothing to install:
The Northwind Database
The examples in this tutorial use the Northwind sample database. It has these tables:
| Table | Records | Contains |
|---|---|---|
| Customers | 91 | The customers of the company |
| Orders | 196 | The orders from the customers |
| OrderDetails | 518 | The products in each order |
| Products | 77 | The products the company sells |
| Categories | 8 | The product categories |
| Suppliers | 29 | The companies that make the products |
| Shippers | 3 | The companies that deliver the orders |
| Employees | 10 | The employees of the company |
Tip: In the editor, click a table name in the "Your Database" list to see all the records in that table.
Install SQLite on Your Computer
To use SQLite on your own computer, you need the sqlite3 command line program:
- Windows: Go to the download page at sqlite.org, and download the zip file with the command line tools (sqlite-tools). Unzip it, and run sqlite3.exe
- macOS: SQLite is already installed. Open the Terminal, and type
sqlite3 - Linux: SQLite is often installed already. On Ubuntu and Debian, you can install it with
sudo apt install sqlite3
Create Your First Database
Start sqlite3 with a file name. If the file does not exist, SQLite creates a new, empty database:
sqlite3 shop.db
Now you can type SQL statements. End each statement with a semicolon:
sqlite> CREATE TABLE Friends (Name TEXT, Age INTEGER);
sqlite> INSERT INTO Friends VALUES ('Emil', 30);
sqlite> SELECT * FROM Friends;
Emil|30
sqlite> .quit
.quit closes sqlite3. The data is saved in the file shop.db, and is still there the next time you open it.
You will learn more about sqlite3 in the SQLite Command Line chapter.
Download the Northwind Database
You can also download the Northwind database, and run the examples from this tutorial on your own computer:
Unzip the file, and open the database with sqlite3:
sqlite3 northwind.db
SQLite in Python
SQLite is built into Python, in the sqlite3 module, so you can use the Northwind database from Python too.
If you have downloaded the Northwind database, put the file northwind.db in the same folder as your Python file. Then write this code in a file, for example mydatabase.py, and run it from that folder with python mydatabase.py:
Example
Select the customers from the UK:
import sqlite3
con = sqlite3.connect("northwind.db")
cur = con.cursor()
cur.execute("""
SELECT CustomerName, City
FROM Customers
WHERE Country = 'UK'
""")
for row in cur.fetchall():
print(row)
con.close()
Run Example »
You will learn more in the SQLite with Python chapter, and step by step in the Python SQLite chapter of our Python Tutorial.
In the rest of this tutorial, we will use our SQLite online editor in all the examples.