CREATE TABLE names columns and types. IF NOT EXISTS keeps a second run from crashing.
Goal
Create cities and products, then list table names.
import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE cities (name TEXT)")
print(con.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall())
con.close()import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE IF NOT EXISTS products (sku TEXT, price REAL)")
con.execute("CREATE TABLE IF NOT EXISTS products (sku TEXT, price REAL)")
print("ok")
con.close()import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE cities (id INTEGER PRIMARY KEY, name TEXT NOT NULL)")
print(con.execute("PRAGMA table_info(cities)").fetchall())
con.close()import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE sales (city TEXT, units INTEGER, price REAL)")
print(con.execute("PRAGMA table_info(sales)").fetchall())
con.close()