In this article, we are going to see how to execute a script in SQLite using Python. Here we are executing create table and insert records into table scripts through Python. In Python, the sqlite3 module supports SQLite database for storing the data in the database.
Step 1: First we need to import the sqlite3 module in Python.
Step 2: Connect to the database by creating the database. We can connect to the database by simply create a database named geeks_db.db or we can simply create a database in our memory by using :memory:
Database creation by name
connection_object = sqlite3.connect(“database_name.db”)
Database creation in Memory:
connection_object = sqlite3.connect:memory:)
Step 3: Create the cursor object after making the database connection.
cursor_object = connection_object.cursor()
Step 4: Write the SQL query that can be executable.
Step 5: Execute the cursor object
Step 6: Get the data inside the table from the database.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course