Folders inside the database: schemas
SQL basics are done — time for the next arc: database management. First up: schemas. So far every table lived in one flat space: weather_stations. But a real database holds hundreds of tables — station readings, county boundaries, model outputs, raw sensor feeds — and flat names get messy fast. A schema is a named folder inside a database that groups related tables under one name: weather.stations, raw.sensor_feed, geospatial.counties.
The code
CREATE SCHEMA weather; CREATE TABLE weather.stations ( station_id TEXT, city TEXT, lat DOUBLE, lon DOUBLE ); SELECT city, lat, lon FROM weather.stations;
Reading it piece by piece:
CREATE SCHEMA weather;— makes the folder. One line, no tables yet — just the namespace.CREATE TABLE weather.stations (...)— creates a table inside the schema, with typed columns. The two-part nameweather.stations(schema.table) is the table's full address.SELECT ... FROM weather.stations;— querying works exactly as before; you just use the full name so the database knows whichstationsyou mean.
In practice
A data engineer uses schemas to keep a big database from turning into a junk drawer. Teams split tables by domain (weather.*, geospatial.*), by team, or by pipeline stage (raw.* for ingested feeds, staging.* for in-progress work, prod.* for curated data). Two wins: no name collisions when two teams both want a table called stations (weather.stations vs telecom.stations), and access control happens per folder — grant a team access to prod instead of hundreds of tables one by one.
Python bridge: a schema is a namespace, exactly like a Python package. weather.stations in SQL is weather.stations in Python — package weather, module stations — and both exist to keep names from colliding across a large codebase.
Further reading
My First Week with SQL: A Beginner's Guide to Building, Filling, and Querying a Real Database — dev.to (the "Create a Schema" section treats a schema as a folder — same mental model)
Try it
Practice question: your hurricane-tracking team just got a new data feed. Write the SQL to: (1) create a schema called storms, and (2) create a table storms.tracks with columns storm_name (TEXT), lat (DOUBLE), lon (DOUBLE), and wind_mph (INT).
Show answer
CREATE SCHEMA storms; CREATE TABLE storms.tracks ( storm_name TEXT, lat DOUBLE, lon DOUBLE, wind_mph INT );
Result: Query OK — the storms schema is created, then the tracks table is created inside it (0 rows affected, since DDL statements don't return rows). Any future table can join it under storms.*, e.g. storms.forecasts.