# Relational Databases with PostgreSQL

> Tables, keys, types and constraints in a real database, and how to load and explore data locally with PostgreSQL. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/data-analyst/relational-databases
Last updated: 2026-11-28

Tables, keys, types and constraints in a real database, and how to load and explore data locally with PostgreSQL.

Beginner · about 5 hours · difficulty 2/5

Learn first: [Joins and Combining Tables](https://www.internhack.in/roadmaps/tracks/data-analyst/sql-joins)

Having your own database to practise on changes how quickly you learn SQL. PostgreSQL is free, standards-compliant and widely used, so it makes an excellent home lab.

### Core concepts

- **Tables** of typed columns: `integer`, `numeric`, `text`, `date`, `timestamp with time zone`, `boolean`, `jsonb`.
- **Primary keys** uniquely identify rows; **foreign keys** link tables and enforce that referenced rows exist.
- **Constraints** (`NOT NULL`, `UNIQUE`, `CHECK`) encode business rules in the database itself.
- **Schemas** group tables (e.g. `raw`, `staging`, `analytics`).

### Getting data in

- `CREATE TABLE` then `COPY` (or psql's `\copy`) from CSV.
- GUI clients like pgAdmin or DBeaver help you browse tables and run queries.
- Alternatives for quick local work: **SQLite** (a single file) and **DuckDB** (fast analytical SQL directly on CSV and Parquet files).

### Views and permissions

Views save a query as a virtual table, great for sharing a cleaned dataset. As an analyst you usually have read-only access to production replicas or warehouses, which is a good thing: never run exploratory queries against a live transactional database without permission.

### OLTP vs OLAP

Transactional (OLTP) databases handle many small reads and writes for apps. Analytical (OLAP) systems handle big scans and aggregations. The same SQL works in both, but the performance characteristics differ.

**Pitfall:** storing numbers or dates as text on import, which breaks sorting and maths. Move on when you can create tables with sensible types and load a CSV into them.

## Key concepts

- **Tables and data types**
- **Primary and foreign keys**
- **Constraints**
- **Loading CSV with COPY**
- **Views**
- **SQL clients: pgAdmin, DBeaver**
- **SQLite and DuckDB for local work**
- **OLTP vs OLAP**

## Mini project

Install PostgreSQL, design three tables for a public dataset (e.g. Olist customers, orders, items), load the CSVs with COPY, add keys, and create a view of completed orders with customer city.

## Check yourself

What does a foreign key protect you from, and why might analytics tables in a warehouse skip them?

## Free resources

- [PostgreSQL tutorial](https://www.postgresql.org/docs/current/tutorial.html) (PostgreSQL)
- [DuckDB documentation](https://duckdb.org/docs/) (DuckDB)

Previous: [Writing Efficient and Readable SQL](https://www.internhack.in/roadmaps/tracks/data-analyst/sql-performance) · Next: [Data Modelling: Normalization and Star Schemas](https://www.internhack.in/roadmaps/tracks/data-analyst/data-modelling)

## More in Databases, Warehouses and Data Modelling

- [Relational Databases with PostgreSQL](https://www.internhack.in/roadmaps/tracks/data-analyst/relational-databases)
- [Data Modelling: Normalization and Star Schemas](https://www.internhack.in/roadmaps/tracks/data-analyst/data-modelling)
- [Cloud Data Warehouses](https://www.internhack.in/roadmaps/tracks/data-analyst/cloud-warehouses)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Data Analyst Roadmap](https://www.internhack.in/roadmaps/tracks/data-analyst)
