How to add a new table in SQLite3 using Python

2 min readSQLiteSQLDataDatabasesStoring Data
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

In order to add a new table, you will need a few things.

  1. Connect to the database
  2. Create a cursor
  3. Add a new table
  4. Commit the changes

Here is the code

import sqlite3

# We connect to the example.db database
con = sqlite3.connect('example.db')

# We create a cursor to perform queries
cur = con.cursor()

# Create a table
cur.execute("CREATE TABLE revenues (date text, amount float, source text)")

# We commit the changes
con.commit()

Congrats! You now know how to add a new table in SQLite using Python.

What you might be interested in

How to install SQLite3 in Python
Learn how to install SQLite 3 in Python
How to create an SQLite3 Database using Python
Learn how to create an SQLite3 database using Python.
How to connect to an SQLite3 database using Python
Learn how to connect to an SQLite3 database using python.
How to add an entry to an SQLite database
Learn how to add an entry to an SQLite database using the execute() method.
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.