BeginnerCoder

Lesson 3 — UNIQUE indexes

UNIQUE indexes enforce rules

An index is not only for speed. A UNIQUE index also guarantees that no two rows share the same value in that column. Trying to insert a duplicate raises sqlite3.IntegrityError, which your code can catch with try / except.

CREATE UNIQUE INDEX idx_cars_plate ON cars(plate)

Why it matters: "one account per email" must be guaranteed by the database itself — checking in app code alone fails when two sign-ups arrive at the same moment.

Want it another way?
Task

Write the CREATE UNIQUE INDEX on users(email). The duplicate sign-up should then be rejected.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.