Member-only story
Using SQL & Python — The Pocket Guide
I haven’t written a lot on coding on my blog, so I thought that since I write upon databases and data analysis, why not write about how to use Python and SQL so that you can manipulate your database easily.
In this pocket guide I would be using SQLite. SQLite is a self-contained, high-reliability, embedded, full-featured, public-domain, SQL database engine. It is the most used database engine in the world wide web.
Python has a library to access SQLite databases, called sqlite3, made to work with this database which has been included with Python package.
Note: Before scrolling/ reading further make sure you are sound with at least basic SQL CRUD statements.
Creating a SQL database connection on Python
Below is the code snippet to just import the sqlite3 python library and create a connection (here my database name is dhaval_test.db
import sqlite3#connecting to the database
connection = sqlite3.connect("dhaval_test.db")#cursor
cursor = connection.cursor()print("Successfully connected to the database")#close the connection
connection.close()