Member-only story

Using SQL & Python — The Pocket Guide

Dhaval Thakur
3 min readAug 13, 2022

--

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.

Using Python and SQL together (Image Credits: DigitalVidhya)

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()

Creating Tables using SQLite and Python

--

--

Dhaval Thakur
Dhaval Thakur

Written by Dhaval Thakur

Data Enthusiast, Geek, part — time blogger. Every week 1 new Data Science/ Product Management story 🖥 I also write on Python, scripting & blockchain

No responses yet