How to add a new table in SQLite3 using Python
• 2 minIn 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.