SQLite is a lightweight, serverless, self-contained SQL database engine. It’s widely used for applications that need a simple, reliable, and efficient database management system. Here are some key features and concepts related to SQLite:
Here are some common SQL commands you might use in SQLite:
Creating a Table:
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER
);
Inserting Data:
INSERT INTO users (name, age) VALUES ('Alice', 30);
Querying Data:
SELECT * FROM users WHERE age > 25;
Updating Data:
UPDATE users SET age = 31 WHERE name = 'Alice';
Deleting Data:
DELETE FROM users WHERE id = 1;
Here’s a simple example of using SQLite with Python:
import sqlite3
# Connect to a database (or create one)
conn = sqlite3.connect('example.db')
c = conn.cursor()
# Create a table
c.execute('''CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)''')
# Insert data
c.execute("INSERT INTO users (name, age) VALUES ('Bob', 25)")
# Commit changes
conn.commit()
# Query data
c.execute("SELECT * FROM users")
print(c.fetchall())
# Close the connection
conn.close()