![]() |
VOOZH | about |
In this article, we are going to see how to execute SQLite statements using Python. We are going to execute how to create a table in a database, insert records and display data present in the table.
In order to execute an SQLite script in python, we will use the execute() method with connect() object:
connection_object.execute("sql statement")
To perform the execution, we have to follow the below steps:
import sqlite3
connection_object = sqlite3.connect('database_name.db')connection_object.execute("sql statement");connection_object.close();
Example 1: Python code to create a database and a table, below are the steps:
Output:
👁 ImageDatabase created:
👁 ImageExample 2: Python code to insert and display data into the above-created table.