Skip to content
    Hack The FutureHack The FuturePython Notes

    UNIT 04 · TOPIC 03

    Creating Tables

    CREATE TABLE defines a table's columns, types and constraints before records are inserted.

    The idea

    Creating Tables, simply explained

    CREATE TABLE defines a table's columns, types and constraints before records are inserted.

    01

    See the big picture

    How the idea flows

    Input or goalCreating TablesPython result
    Understand the problemApply Creating TablesRun the codeCheck the output

    Read the diagram as a simple path: begin with a problem, use the Python idea, then verify the result.

    02

    Everyday connection

    Real-life example

    ↗

    A school creates a Student table with an ID, name and email before enrolling students.

    03

    Learn by doing

    Python code example

    PYTHONExample
    import sqlite3
    db = sqlite3.connect(':memory:')
    db.execute('CREATE TABLE student (id INTEGER, name TEXT)')
    print(db.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchone()[0])
    Expected resultstudent
    Try it: Change one value in the code, predict what will happen, then run it and compare your answer.
    04

    Keep this in mind

    Key takeaways

    • CREATE TABLE defines a table's columns, types and constraints before records are inserted.
    • Think of a real problem where creating tables could save time or organize information.
    • Test small changes and read the result carefully before moving to a bigger program.

    Quick self-check

    Can you explain it in your own words?

    What is the main idea of Creating Tables?

    CREATE TABLE defines a table's columns, types and constraints before records are inserted.

    Where could you see this idea in everyday life?

    A school creates a Student table with an ID, name and email before enrolling students.

    Keep learning · Hack The Future