Python SQLite - Create Table Last Updated : 01 Jul, 2025 Comments Improve Suggest changes 5 Likes Like Report In this article, we will discuss how can we create tables in the SQLite database from the Python program using the sqlite3 module. SyntaxCREATE TABLE table_name ( column1 datatype PRIMARY KEY, column2 datatype, column3 datatype, ... columnN datatype);table_name: name of the table you want to create.column1, column2, ..., columnN: columns you want to include in your table.datatype: type of data that will be stored in each column (e.g., INTEGER, TEXT, REAL, etc.).PRIMARY KEY: column (or set of columns) that uniquely identifies each row in the table.Steps to Create a Table in SQLite using PythonImport the SQLite3 Module: Use import sqlite3 to access SQLite functionality in Python.Establish Connection: Use the connect() method to establish a connection to your SQLite database.Create a Cursor Object: The cursor() method creates a cursor object that allows you to execute SQL commands.Execute SQL Query: The execute() method of the cursor object is used to run the SQL CREATE TABLE command.Close the Connection: After executing the required commands, it is essential to close the connection to the database.Implementation: Python import sqlite3 # Connect to the SQLite database (or create it if it doesn't exist) connection_obj = sqlite3.connect('geek.db') # Create a cursor object to interact with the database cursor_obj = connection_obj.cursor() # Drop the GEEK table if it already exists (for clean setup) cursor_obj.execute("DROP TABLE IF EXISTS GEEK") # SQL query to create the table table_creation_query = """ CREATE TABLE GEEK ( Email VARCHAR(255) NOT NULL, First_Name CHAR(25) NOT NULL, Last_Name CHAR(25), Score INT ); """ # Execute the table creation query cursor_obj.execute(table_creation_query) # Confirm that the table has been created print("Table is Ready") # Close the connection to the database connection_obj.close() Output:Explanation:sqlite3.connect('geek.db') connects to the geek.db database. If it doesn't exist, it's created.connection_obj.cursor() creates a cursor object to interact with the database.cursor_obj.execute("DROP TABLE IF EXISTS GEEK") removes the GEEK table if it already exists, ensuring a clean setup.The SQL query CREATE TABLE GEEK defines the structure of the table with columns Email, First_Name, Last_Name, and Score and their respective data types.cursor_obj.execute(table_creation_query) runs the SQL command to create the table.connection_obj.close() closes the connection to the database after the operation is complete. Comment M maheswaripiyush9 Follow 5 Improve M maheswaripiyush9 Follow 5 Improve Article Tags : Python Python-SQLite Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like