How to add a new table in SQLite3 using Python

2 min

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.