How to create the new database in Sqlite using Python

SQLite in Python

SQLite is a lightweight disk-based storage that doesn’t require separate server process in python.Some application can use Sqlite for internal data storage. We can just import the sqlite3 module to create the database in our system. The data will be stored in the database_name.db file.

Create a new database in Sqlite using python

Sqlite3.connect(‘<database_name>’)

The connect() function of sqlite module is used to create the connection object to create the database. If the database is opened successfully, it returns the connection object.

connection.cursor()

Once you have create the connection, you can create the cursor object to execute the SQL commands.

cursor.execute()

The execute() function will only execute a single SQL statements on Sqlite database. If you try to execute more than one statement with it, it will raise a Warning.The sqlite3 module supports two kinds of placeholders in the execute function: question marks (qmark style) and named placeholders (named style).

connection.close()

It will close the database connection. The cursor will be unusable from this point forward

Output of this program

Create a database in Sqlite using python
Create a database in Sqlite using python

Inserting and fetch the data from SQLite database using python

Here we have used Sqlite3 module to create the database in our local system. The json module is used to load the json string into python variable.

Once we have established the database connection, We can execute the SQL commands such as INSERT,SELECT queries in the employee_details table.

Output