Python Practice › SQLite Programs
Python SQLite Programs with Solutions
20 SQLite programs using Python’s built-in sqlite3 module: creating tables, inserting with parameters, querying, updating, deleting, joins, aggregates, transactions and exporting to CSV. Most use an in-memory database so they run anywhere.
Before you start
Read the SQLite lesson first if the topic is new to you.
All programs
- #1Create a table
Write a Python program to create a SQLite table and list the tables in the database.Easy - #2Insert a row with parameters
Write a Python program to insert a row safely with?placeholders.Easy - #3Insert many rows
Write a Python program to insert several rows at once.Easy - #4Select with a condition
Write a Python program to select students who scored above 80.Easy - #5Update rows
Write a Python program to add 5 bonus marks to students below 80.Easy - #6Delete rows
Write a Python program to delete students with marks below 70.Easy - #7fetchone, fetchmany, fetchall
Write a Python program that shows the three fetch methods.Easy - #8Rows as dictionaries
Write a Python program to read rows by column name.Easy - #9Aggregate functions
Write a Python program to get the count, average, minimum and maximum marks.Easy - #10Group by
Write a Python program to count employees and average salary per department.Easy - #11Join two tables
Write a Python program to list each order with the customer’s name.Medium - #12Customers without orders
Write a Python program to find customers who have not placed any order.Easy - #13Transaction with rollback
Write a Python program that transfers money between accounts and rolls back on error.Easy - #14Use a database file
Write a Python program that saves data to a .db file and reads it back with a new connection.Easy - #15Column names of a query
Write a Python program to print the column names of a query result.Easy - #16Search with LIKE
Write a Python program to find products whose name contains a word.Easy - #17Top N rows
Write a Python program to get the top 3 scores.Easy - #18Export a table to CSV
Write a Python program to export a table to a CSV file.Easy - #19Why parameters prevent SQL injection
Write a Python program that shows how an f-string query is unsafe and a parameter is safe.Easy - #20Query into pandas
Write a Python program to load a query result into a pandas DataFrame.Easy