What is a database?
Before databases were widely used, applications often stored information directly in files. Imagine a telephone directory kept in a file named telephone_directory.csv:
For a small amount of information, a file works perfectly well: a program opens it, reads the contents, and searches for the record it needs. As the data grows and more applications and users work with it, several problems appear.
Why plain files struggle as data grows
Every question needs custom code
A file stores data but offers no way to ask questions of it. Each new question (“Asha’s number,” “who lives at 12 Lake Road?”) means writing another file-scanning program.
Search slows as the file grows
Reading millions of records to find a match is slow. Databases build indexes that locate matching rows efficiently, by name, phone, address, or city.
Safe updates are hard
Changing one number means finding the record, rewriting the file, and not corrupting the rest, especially when several users write at once.
Duplication drifts out of sync
When the same details are repeated across rows, updating one copy and missing another leaves conflicting information.
Files enforce no rules
Nothing stops a duplicate identifier, a missing name, or an invalid phone number. Databases define constraints that reject bad data.
Relationships aren’t guaranteed
Nothing ensures a person_id in one file exists in another. A relational database enforces the link and rejects orphaned records.
Access is all-or-nothing
File permissions grant the whole file or none of it. Databases grant access per table, per operation, per view, and per role.
Recovery after a crash is hard
A crash mid-write can leave a half-updated file. Databases use transactions, logs, and backups so a set of changes completes fully or is safely undone.
Two problems, made concrete
Duplication drifts into conflict
Storing a row per phone number repeats Asha’s name and address. If she moves and only one row is updated, the file now disagrees with itself:
A relational database stores the person once and connects several phone numbers to that single record.
Files enforce no rules
Suppose every person must have a unique id, a name, a valid phone number, and a city. A plain file happily accepts none of that:
The id 1 is duplicated, unknown is not a phone number, Ben’s city is missing, and the third record has no name. A database’s constraints can require values, forbid duplicate identifiers, and restrict data types.
What a database provides
A database is an organised collection of related information. The software that stores, retrieves, updates, and protects it is a Database Management System, or DBMS: for example PostgreSQL, MySQL, Microsoft SQL Server, Oracle Database, or SQLite.
A DBMS helps applications store structured information, search large volumes quickly, update records safely, support many concurrent users, reduce duplication, enforce data-quality rules, maintain relationships, control access, and recover from failure.
Information organised into related tables
In the relational model, information lives in tables. Each table represents one kind of thing, holding rows (individual records) and columns (their attributes). An orders table might look like this:
Product and customer details do not need to be repeated inside every order. They live in their own tables, connected by shared identifiers.
Order 1001 stores product_id = 101 and customer_id = 1. Looking those up tells us Asha ordered a Wireless Mouse, without repeating her details or the product’s in every order row.
How the tables relate: keys
The three tables describe one business process, Customers → Orders → Products, linked through shared identifying columns called keys.
Primary key
Uniquely identifies each row in a table, for example customers.customer_id or orders.order_id. No two rows share the same value.
Foreign key
Refers to a row in another table. orders.customer_id points at customers.customer_id, and orders.product_id points at products.product_id.
Thinking in rows and columns
Most questions become questions about tables, rows, columns, and relationships:
- Which orders have been paid? Filter
ordersbystatus. - Which products cost more than 2,000? Filter
productsbyprice. - Which products has Asha ordered? Combine
customers,orders, andproducts. - How much revenue did each product generate? Combine orders and products, compute an amount, and group by product.
What is SQL?
SQL (pronounced “S-Q-L” or “sequel”) stands for Structured Query Language, the language commonly used to work with relational databases. It lets you describe the information you want without spelling out every step to retrieve it.
The query states which columns you want, which table holds them, and which rows to include. The database decides how to run it efficiently. This is what it means to call SQL a declarative language.
Imperative: every step
Open the table, read the first row, check the price, keep it when above 2,000, repeat until every row is checked.
Declarative: the result
“The id, name, and price of products priced above 2,000.” You state what you want; the database works out the steps.
What you can do with SQL
SQL does more than read data. It can filter, sort, combine, summarise, add, update, remove, and even define the structure of information in a relational database.
Because of this, SQL is used by software engineers, data analysts, data engineers, database administrators, data scientists, and business teams alike. The same core ideas appear across PostgreSQL, MySQL, SQL Server, Oracle, SQLite, Snowflake, BigQuery, and DuckDB; the exact syntax varies, but the relational concepts stay the same.
A SQL query returns another table
An important idea: the result of a query is itself a table. Running:
Nothing was removed from the database. The query produced a new table containing only the requested rows and columns. As queries grow, they follow the same shape: begin with one or more tables, filter unwanted rows, combine related tables, calculate new values, group similar rows, sort, and return a new table.
What comes next
We build SQL knowledge gradually, from the operations used in everyday queries toward more advanced analytical patterns.
The goal is not only SQL that runs. It is SQL that expresses the business requirement clearly, returns the correct result, and stays understandable when someone reads it later.