SQL : Transactions and different isolation levels

What are SQL Transactions ?

Simply, transactions are group of SQL code that represents single unit of work

Properties of transactions

A -> Atomicity
C -> Consistency
I -> Isolation
D -> Durability
To understand what are isolation levels and why do we need to consider them we first need to know about concurrency

Concurrency

Accessing same data by different users
When multiple transactions execute concurrently then it might lead to several problems. Here is a table representing different isolation levels and problems they solve,

image.png Source : CodeWithMosh
Be aware of using isolation levels, as they will effect performance significantly.
MYSQL uses Repeatable Read by default , only change transaction level if you have a really good reason.
To change the transaction level in MYSQL
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
Alternatively we can use
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
-- lasts until end of session
SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED