Create a Students Table
Intermediate · Write the code · from Python SQLite: Build and Query Databases Without a Server
From the lesson: Python SQLite: Build and Query Databases Without a Server
Every app needs to store data somewhere. A to-do list needs to remember your tasks. A contacts app needs to save names and phone numbers. You could write everything to a text file, but what happens when you need to find all contacts in a specific city, or delete tasks older than a week?
Read the lessonCreate an in-memory SQLite database with a students table having columns id (INTEGER PRIMARY KEY AUTOINCREMENT), name (TEXT), and grade (INTEGER). Insert three students: Alice (grade 90), Bob (grade 85), Charlie (grade 92). Then select and print all students in the format name: grade.
import sqlite3
conn = sqlite3.connect(':memory:')
cursor = conn.cursor()
# Create the students table
# Insert three students
# Select and print all students
conn.close()
More SQLite exercises
- Filter Products by PriceIntermediate
- Predict the Query ResultIntermediate
- Manage an InventoryIntermediate
- Fix the SQL Injection BugIntermediate
- Build a Contact BookAdvanced
All Python exercises · 50 practice problems · Standard Library Essentials quiz