SQL - MySQL

Module 01 - Database Theory
1. Introduction to Databases2. DBMS Theory Concepts3. Types of Keys4. Database Relationships5. DBMS Interview Questions
Module 02 - CRUD Operations
1. Create - INSERT2. Read - SELECT3. Update - UPDATE4. Delete - DELETE5. Alter - ALTER TABLE
MySQL Playground
Profile
Akkal DhamiFull Stack Developer

Building modern web experiences with a focus on performance, scalability, and clean architecture.

© 2026 | Akkal Dhami | All rights reserved

Built with
byAkkal Dhami

Navigation

  • Projects
  • Dev Setup
  • Playbook
  • Templates
  • Networking
  • SQL - MySQL
  • SQL Playground
  • DSA
AKKAL DHAMIAKKAL DHAMIAKKAL DHAMI

DBMS Theory Concepts

These are the core ideas every relational database is built on. Understanding them makes everything you do later — tables, queries, joins — click into place faster.


Relational vs Non-Relational Databases

A relational database stores data in tables made of rows and columns, connected to each other through relationships. A non-relational database stores data in more flexible shapes, like documents or key-value pairs.

AspectRelational (SQL)Non-Relational (NoSQL)
StructureFixed schema, tables with rows and columnsFlexible schema, documents or key-value pairs
RelationshipsEnforced via foreign keysUsually handled in application code
ConsistencyStrong, follows ACIDOften eventual consistency
ExamplesMySQL, PostgreSQL, SQL ServerMongoDB, Redis, Cassandra

Neither is "better" — relational fits data with clear structure and relationships (like orders linked to customers); non-relational fits data that's flexible or changes shape often.


Tables, Rows, and Columns

A table represents one type of thing — for example books or customers. Each row in that table is one specific record. Each column is one attribute shared by every row.

Example: in a books table, each row is one book, and columns like title, author, and price describe that book.


Schema

The schema is the blueprint of a database — which tables exist, what columns they have, what data types those columns use, and how tables relate to one another.

Think of the schema as the architecture plan drawn up before any actual data (rows) gets added.


Keys

Keys are how rows are uniquely identified and how tables connect to each other.

Key TypeWhat it doesExample
Primary KeyUniquely identifies each row in a table; can't be empty or duplicatedid in books
Foreign KeyA column that references a primary key in another table, creating a relationshipcustomer_id in orders referencing id in customers
Composite KeyA primary key made of two or more columns combinedorder_id + product_id in an order_items table
Candidate KeyAny column (or set of columns) that could qualify as the primary keyemail in customers, if it's unique

Normalization

Normalization is the process of organizing tables to avoid storing the same information more than once.

Without normalization: every row in an orders table repeats the customer's full name and address.

With normalization: the customer's details live once in a customers table, and orders just stores a customer_id pointing to it.

Why it matters:

  • Avoids inconsistencies (the same customer's name spelled two different ways in two rows)
  • Saves storage space
  • Makes updates easier — change the customer's address once, not in every order

Normalization is usually described in stages called normal forms (1NF, 2NF, 3NF), each removing a specific kind of duplication. At a basic level, just remember the core idea: one fact, stored in one place.

Learn more about normalization


ACID Properties

ACID is a set of guarantees that a reliable database follows whenever it makes changes to data.

LetterPropertyMeaning
AAtomicityA group of changes either all happen, or none happen — no partial updates
CConsistencyData always follows the rules defined (types, constraints, relationships)
IIsolationMultiple operations happening at the same time don't interfere with each other
DDurabilityOnce a change is saved, it survives even a crash or power loss

Simple example: transferring money between two bank accounts involves subtracting from one and adding to the other. Atomicity guarantees both happen together — you'll never end up with money deducted from one account but not added to the other.


Constraints

Constraints are rules attached to columns that stop invalid data from being saved.

ConstraintWhat it enforces
NOT NULLColumn can never be left empty
UNIQUENo two rows can share the same value in this column
CHECKValue must satisfy a specific condition before it's saved
DEFAULTSupplies a fallback value when none is given
FOREIGN KEYValue must match an existing value in another table's key column

Indexes (brief preview)

An index is a structure that speeds up how quickly the database can find rows — similar to an index at the back of a book. Indexes make reads faster but add a small cost to writes. This gets covered in depth in the Performance module, but it's worth knowing the term exists.


Client-Server Model

A database like MySQL runs as a server — a background process managing the actual data. Anything that connects to it — a terminal, an app, VS Code — is a client sending it commands. All reads and writes go through the server, which is what keeps the ACID guarantees intact even when many clients connect at once.

Learn more about the client-server model


Quick Recap

ConceptOne-line summary
SchemaThe blueprint of tables, columns, and relationships
Primary KeyUniquely identifies a row
Foreign KeyLinks one table to another
NormalizationStore each fact once, avoid duplication
ACIDGuarantees that keep data safe and consistent
ConstraintA rule that blocks invalid data
IndexSpeeds up finding rows