Puzzle Computer Science Databases
Beginner
80 mins
Teacher/Student led
What you need:
Chromebook/Laptop/PC

Introduction to SQLite Databases

In this lesson, you'll explore the essentials of databases by setting up SQLite in your Flask project. Learn to create a database, define tables, insert data via forms, and test data persistence, ensuring information remains even after app restarts.
Learning Goals Learning Outcomes Teacher Notes

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Introduction

    In this lesson, you'll learn the basics of databases by setting up SQLite in your Flask project.

    SQLite is a lightweight database that stores data in a file, perfect for small projects. You'll create a database file, define a table for user data, and insert records via a Flask route handling POST requests from a form. You'll focus on connecting to the database, running basic SQL commands, and testing that data persists even after restarting the app.

    By the end, you'll understand how to store and retrieve persistent data in a web backend. Here's what you'll do:

    1. Set up your project.
    2. Create a SQLite database and table.
    3. Build a form and route to insert data.
    4. Test data persistence.

    2 - Create a Project Folder

    To keep your work organised, start by creating a new folder for this lesson's project.

    1. On your computer, create a new folder named 'FlaskSQLiteIntro'.
    2. Open VS Code and select File > Open Folder, then choose 'FlaskSQLiteIntro'.

    With your folder ready, next you'll set up the virtual environment.

    3 - Create the Virtual Environment

    Create a virtual environment to manage your project's dependencies.

    1. Open the Command Palette: View > Command Palette.
    2. Type 'Python: Create Environment' and select it.
    3. Choose 'Venv'.
    4. Select your Python version.
    5. VS Code will create a '.venv' folder.

    4 - Install Flask

    Open a terminal in VS Code to install Flask.

    1. Go to View > Terminal.
    2. Run: pip install flask.
    3. Wait for the installation to complete. 
    Note: SQLite is built into Python, so no extra installation is needed.

    5 - What is a Database?

    A database is a structured collection of data that is organised in a way that makes it easy to store, retrieve, update, and manage information. Think of it like a digital filing cabinet where data is kept in an orderly fashion, allowing computer programs to access it quickly and efficiently.

    Basic Concepts:

    • Tables: Data is stored in tables, similar to spreadsheets. Each table has rows and columns.
    • Rows and Columns: A row (also called a record) represents a single entry, like one user's details. Columns (or fields) define the types of data, such as 'name' or 'age'.
    • Primary Key: A unique identifier for each row, like an ID number, to ensure no duplicates and enable quick lookups.
    • Queries: Commands written in a language like SQL (Structured Query Language) to interact with the database, such as inserting new data, selecting specific records, or updating existing ones.
    • Data Types: Specifies what kind of data can be stored in a column, e.g., text for names, integers for ages.

    What Databases Are Used For: In computer systems and computer science, databases are essential for handling large amounts of data persistently – meaning the data remains even after the program stops running. They power websites (storing user accounts), mobile apps (saving settings), business systems (managing inventory), and more. Without databases, applications would lose data every time they restart, making them impractical for real-world use. In this lesson, you'll use SQLite, a simple database, to see these concepts in action within a web app.

    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of DigitalSkills.org. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more