Python Practice › SQLite Programs › Program 3
Insert many rows
Write a Python program to insert several rows at once.
Output
4
Approach
executemany.
Solution
import sqlite3 conn = sqlite3.connect(":memory:")conn.execute("CREATE TABLE students (name TEXT, marks INTEGER)")rows = [("Asha", 91), ("Ravi", 74), ("Meena", 88), ("John", 65)]conn.executemany("INSERT INTO students VALUES (?, ?)", rows)print(conn.execute("SELECT COUNT(*) FROM students").fetchone()[0])Output
4
Learn the concept
New to this topic? Read the lesson, then come back.