BeginnerCoder

Lesson 2 — Insert rows

Adding rows with INSERT

INSERT INTO adds a row. The values go in the same order as the table's columns. Text values need single quotes inside SQL. To insert many rows safely, use placeholders — a ? for each value — and pass the data separately with executemany(). The database fills in the values itself, so a name like O'Brien cannot break your SQL.

db.execute("INSERT INTO pets VALUES (?, ?, ?)", (1, "Rex", "dog"))

These lessons run a real SQLite database inside Python (the built-in sqlite3 module), all in your browser.

Why it matters: placeholders are not just convenient — they protect you from SQL injection, one of the most common ways websites get hacked.

Want it another way?
Task

Fill in the INSERT with two ? placeholders so executemany adds all three people. Expected: 3 rows printed.

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.