SQLite Create Database
A Database is a File
Most databases have a CREATE DATABASE statement. SQLite does not, because an SQLite database is just a file.
To create a new database, you open a file that does not exist yet. SQLite then creates an empty database in that file.
Create a Database With sqlite3
Start the sqlite3 command line program with the name of the new file:
sqlite3 shop.db
If sqlite3 is already running, use the .open command:
sqlite> .open shop.db
Note: The sqlite3 program does not create the file before you create something in it, like a table.
Create a Database With Python
In Python, sqlite3.connect() opens the file, and creates it if it does not exist:
import sqlite3
con = sqlite3.connect("shop.db")
A Database in Memory
The special name :memory: creates a database in memory, not in a file. It is fast, but it is gone when the program ends:
sqlite3 :memory:
Our online editor uses a database in your browser, so nothing is saved on a server.
Delete a Database
There is no DROP DATABASE statement in SQLite. To delete a database, close all the programs that use it, and delete the file.