Python Practice › SQLite Programs › Program 6
Delete rows
Write a Python program to delete students with marks below 70.
Output
deleted: 1 [('Asha',), ('Ravi',)]Approach
DELETE FROM ... WHERE ....
Solution
import sqlite3 conn = sqlite3.connect(":memory:")conn.execute("CREATE TABLE students (name TEXT, marks INTEGER)")conn.executemany("INSERT INTO students VALUES (?, ?)", [("Asha", 91), ("Ravi", 74), ("John", 65)])cur = conn.execute("DELETE FROM students WHERE marks < 70")print("deleted:", cur.rowcount, conn.execute("SELECT name FROM students").fetchall())Output
deleted: 1 [('Asha',), ('Ravi',)]Learn the concept
New to this topic? Read the lesson, then come back.