Connecting to a SQLite database with sqlite3
Opens the SQLite database file school.db (creating it if missing) and returns a connection. Then conn.cursor() makes a cursor to run SQL, and conn.close() ends the connection.
Understanding Connecting to a SQLite database with sqlite3 in QCE Digital Solutions Unit 4
What it does: import sqlite3 loads the built-in SQLite library so that sqlite3.connect() can be used. conn.close() ends the connection to the database file once the program is done with it. connect() creates the database file if it is missing. This is why a typo in the file name can quietly make a new empty database. The cursor is made from the connection object (conn), not from the sqlite3 module. You need a connection before you can make a cursor, and you must run your SQL before closing the connection. The module name is all lowercase and includes the 3: sqlite3. Python is case sensitive.
Common mistakes: close is a method, so it needs brackets to run. It should be conn.close() to end the connection. A cursor is made from the connection object, not the sqlite3 module. It should be cur = conn.cursor().
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 334–401) and word search (Modules 127–401).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
conn = sqlite3.connect("school.db")Fill in the Blanks
Spot the Error
Student with a class code? Join your class →