Insert many rows

EasySQLite Programs · 3 of 20

Write a Python program to insert several rows at once.

Advertisement
Output
4

Approach

  1. executemany.

Solution

Python
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.

More sqlite programs

← All 20 SQLite Programs

Leave a Comment