Python HOW: Connect to, and Manage a Database

Image for post
Image for post
Photo by panumas nikhomkhai from Pexels

I’ve put my best effort to provide you with a clear, concise, and detailed description on how to connect to, and manage a SQL/SQLite database using Python

Introduction

A database is often referred to by the DBMS used to manipulate it. For example, a database that is manipulated using Microsoft SQL Server is referred to as: Microsoft SQL Server-Database

PyODBC: Open DataBase Connectivity for Python

You might want to create a virtual environment first
You can find information about general connection string for most databases here. Make sure to follow the connection string formatting rules found here

SQLite3: SQLite for Python

If the database does not exist, an empty one will be created for us

Executing SQL statements

Docs for cursor

SELECT statement

UPDATE statement

DELETE statement

INSERT INTO statement

Long SQL statement

What is next?

Written by

I’m an End-to-End data scientist and a Python educator. Most of my articles start after saying “I wish someone has written about this!”, maybe I should?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store