Database and SQL Basics
Original educational reference document
Relational Databases
A relational database stores information in tables made of rows and columns. Tables
can be related through keys.
Primary and Foreign Keys
A primary key uniquely identifies a row. A foreign key references a key in another table
and can represent relationships between records.
SELECT
SELECT retrieves data. WHERE filters rows, ORDER BY sorts results, and LIMIT
restricts the number of returned rows.
INSERT, UPDATE, DELETE
INSERT adds rows. UPDATE changes existing rows. DELETE removes rows. Always
use a precise WHERE clause when modifying or deleting selected records.
JOINs
INNER JOIN returns matching rows from related tables. LEFT JOIN keeps every row
from the left table and adds matching data from the right table when available.
Aggregation
COUNT, SUM, AVG, MIN, and MAX summarize data. GROUP BY creates groups for
aggregation, while HAVING filters grouped results.
Database Design
Good design reduces unnecessary duplication and makes relationships clear.
Constraints such as NOT NULL, UNIQUE, and FOREIGN KEY help protect data quality.