Web Analytics

SQLite Database

Advanced ~15 min read

Python comes with built-in support for SQLite, a lightweight disk-based database. It doesn't require a separate server process.

Basic Operations

The sqlite3 module provides an SQL interface compliant with the DB-API 2.0 specification.

Output
Click Run to execute your code

Exercise: Products Table

Task: Create a products table and insert data.

Requirements:

  • Create table products (id, name, price).
  • Insert 'Laptop' with price 999.99.
  • Select and print all products.
Output
Click Run to execute your code
Show Solution
c.execute("CREATE TABLE products (id INTEGER PRIMARY KEY, name TEXT, price REAL)")
c.execute("INSERT INTO products (name, price) VALUES ('Laptop', 999.99)")
c.execute("SELECT * FROM products")