How to add a new table in SQLite3 using Python
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
In order to add a new table, you will need a few things.
- Connect to the database
- Create a cursor
- Add a new table
- 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
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
Related Articles
Continue your learning journey with these related topics
SQLite
2 min readHow to retrieve data entries from SQLite3 using Python
How to retrieve data entries from an SQLite3 Database using the built-in sqlite3 library. An easy way to store data in a SQL-ready storage system.
8/5/2022Read More
SQLite
2 min readHow to add an entry to an SQLite database
Learn how to add an entry to an SQLite database using the execute() method.
8/5/2022Read More
SQLite
2 min readHow to use SQLite3 in Python
Learn how to use SQLite3 with Python using the built-in library sqlite3.
8/4/2022Read More
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