Create, Alter, Drop a Table
For the creation, modification, or deletion of a database object, such as a table or sequence, use the execute() method.
Create
Below, you’ll find an example of how to create a table:
createTable = "CREATE TABLE person (
id BIGINT NOT NULL,
name VARCHAR,
lastName VARCHAR,
birth_date DATE,
passport VARCHAR,
phone VARCHAR,
PRIMARY KEY (id)
)"
try:
cursor = conn.cursor()
cursor.execute(createTable)
conn.commit()
except Exception as e:
print("Error:", e)
finally:
cursor.close()